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?
How to import `.a` file to CMake in C++?
Asked Answered
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})
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 prefixes –
Jessamine
© 2022 - 2024 — McMap. All rights reserved.
libBox2D.a
using CMake. – Frantic