Cmake basic library linking problem

2019-05-10 08:20发布

I have a simple problem with the linking of libraries with CMake (I don't know CMake very well). My configuration is the following :

project/src/CMakeLists.txt (with all .cpp and .h files)
project/support/linux/gmp/include/gmp.h
project/support/linux/gmp/include/gmpxx.h
project/support/linux/gmp/include/libgmp.a
project/support/linux/gmp/include/libgmpxx.a

How to include the library gmp in the process of compilation ? (I am lost between FIND_PACKAGE, INCLUDE_DIRECTORIES, TARGET_LINK_LIBRARIES, ADD_LIBRARY ... commands)

Thank you very much.

标签: linker cmake
1条回答
放荡不羁爱自由
2楼-- · 2019-05-10 08:37

CMake is not so hard to understand.

First Step

Use find_package to locate the libary.

find_package(GMP REQUIRED)

Second step

Use include_directories to include the libary header files.

include_directories(${GOBJECT_INCLUDE_DIR})

Third Step

Use target_link_libraries to link your binary against the libary.

add_executable(ExecutableName Main.cpp)
target_link_libraries(ExecutableName ${GOBJECT_LIBRARIES})
查看更多
登录 后发表回答