6

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?

Szymon Marczak
  • 1,055
  • 1
  • 16
  • 31

1 Answers1

6

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})
grigor
  • 1,584
  • 1
  • 13
  • 25
  • And then I can use Box2D? Do I have to do `#import ` or something? – Szymon Marczak Aug 09 '16 at 18:57
  • 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 ` where you replace the file with whatever header file you need from Box2D. – grigor Aug 09 '16 at 19:01
  • So, only what I need to do is include source code (or only headers?) and link `libBox2D.a`? – Szymon Marczak Aug 09 '16 at 19:45
  • 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. – grigor Aug 09 '16 at 20:43
  • It worked. Thanks! – Szymon Marczak Aug 10 '16 at 08:41
  • Also target_link_libraries(v4l2 /usr/lib/libv4l2wrapper.a ) works, without prefixes – nerkn Jan 22 '22 at 09:29