![]() While CMake enjoys increasing interest, there are still plenty of libraries using native build systems like Unix Makefiles. Including external libraries using other build systems CMake will make sure to first build test before linking it to myapp. In target_link_libraries we tell CMake to link it to our executable. ![]() Now, we can use the library defined in CMakeLists.txt of libtest_project in myapp’s CMakeLists.txt: cmake_minimum_required(VERSION 2.8) project(myapp) add_subdirectory(libtest_project) add_executable(myapp main.c) target_link_libraries(myapp test) install(TARGETS myapp DESTINATION bin)Īdd_subdirectory makes the library test defined in libtest project available to the build. Let’s start by adding the library’s directory as a subdirectory to our myapp project. We can extend our executable from above by linking it to our libray libtest.a. Instead of a static library we can build a shared lib as well: add_library(test SHARED test.c) Linking libraries to executables with CMake ![]() We also include our public header file into the install step and tell cmake to put it into include. To build a library we use a similar script: cmake_minimum_required(VERSION 2.8) project(libtest_project) add_library(test STATIC test.c) install(TARGETS test DESTINATION lib) install(FILES test.h DESTINATION include)ĬMake will build the library as libtest.a and install it into lib folder of the install directory. This will output a readily configured Xcode project to build our app. If we wanted to use a different generator we pass it to cmake using the -G parameter: cmake. We can now run our binary from the install directory. To run the build script you can simply use the Makefile: make make install
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |