How to import `.a` file to CMake in C++?
Asked Answered
F

1

7

I've generated libBox2D.a. Now I want to import it to C++ project, but I don't know how. How I can import my libBox2D.a to my project using CMake?

Frantic answered 9/8, 2016 at 18:49 Comment(1)
Hmm... I don't think this question is too broad. It has only one topic: import libBox2D.a using CMake.Frantic
C
7

Try this:

find_library(LIBBOX2D Box2D DIRECTORY)

where replace DIRECTORY with the location of libBox2D.a. Then you can link this library to your executable:

target_link_libraries(exec ${LIBBOX2D})
Counterglow answered 9/8, 2016 at 18:54 Comment(6)
And then I can use Box2D? Do I have to do #import <Box2D> or something?Frantic
In you cmake file you should write something like include_directories(dir) where you replace dir with the directory of the header files of Box2D. Then in your source code you will do #include <file> where you replace the file with whatever header file you need from Box2D.Counterglow
So, only what I need to do is include source code (or only headers?) and link libBox2D.a?Frantic
Depends on what you're trying to do. I'm assuming you know how you want to use Box2D. I don't really know what it does. Here my answer is about how to include that external library into your project using cmake. The rest is up to you - how you want to use it and what code you want to write with it.Counterglow
It worked. Thanks!Frantic
Also target_link_libraries(v4l2 /usr/lib/libv4l2wrapper.a ) works, without prefixesJessamine

© 2022 - 2024 — McMap. All rights reserved.