Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to import `.a` file to CMake in C++? [closed]

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?

like image 836
Szymon Marczak Avatar asked Aug 09 '16 18:08

Szymon Marczak


People also ask

How do I import to CMake?

In the CMakeLists file, use the add_executable() command to create a new target called myexe . Use the IMPORTED option to tell CMake that this target references an executable file located outside of the project. No rules will be generated to build it and the IMPORTED target property will be set to true .

What is a .CMake file?

A CMAKE file is a project file created by the open-source, cross-platform tool CMake. It contains source script in the CMake language for the entire program. CMake tool uses programming scripts, known as CMakeLists, to generate build files for a specific environment such as makefiles Unix machine.


1 Answers

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})
like image 148
grigor Avatar answered Sep 22 '22 18:09

grigor