开发者

CMAKE linking to system library

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜