开发者

CMAKE linking to system library

开发者 https://www.devze.com 2023-04-11 14:04 出处:网络
We would like to build a shared library with CMAKE system. It\'s something like: lib/ CMakeLists.txt src/

We would like to build a shared library with CMAKE system. It's something like:

lib/
  CMakeLists.txt
  src/
    CMakeLists.txt
    module/
      CMakeLists.txt
      module1.c
    foo.c

module1.c needs some standard shared library like librt. We have

add_library(module module1.c)
target_link_libraries(module rt)

in the modu开发者_如何转开发le/ sub-directory. But still getting errors that stuff from librt is not known.


If librt is linked with -lrt, then in CMake you can link it in this way:

target_link_libraries(module -lrt)


Actually what you are doing should work. If the compiler cannot find the library it may simply not be in the standard library paths. You can use the following help to specify different link_directories (-L/some/path parameter to the compiler).

cmake --help-command link_directories

Another useful thing you can do while debugging CMake builds is print out the commands it runs the compiler with:

make VERBOSE=1

You can then take the commands and manually tailor them to work. After that it is a matter of modifying CMAKE_C_FLAGS/include_directories/link_directories

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号