【问题标题】:CMAKE linking to system libraryCMAKE 链接到系统库
【发布时间】:2011-10-09 10:52:32
【问题描述】:

我们想用CMAKE 系统建立一个共享库。是这样的:

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

module1.c 需要一些标准共享库,例如librt。我们有

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

module/ 子目录中。但仍然收到来自librt 的内容未知的错误。

【问题讨论】:

    标签: c++ c cmake


    【解决方案1】:

    如果 librt 与 -lrt 链接,那么在 CMake 中可以这样链接:

    target_link_libraries(module -lrt)
    

    【讨论】:

    【解决方案2】:

    实际上,您正在做的事情应该有效。如果编译器找不到库,它可能根本不在标准库路径中。您可以使用以下帮助指定不同的link_directories(编译器的-L/some/path参数)。

    cmake --help-command link_directories
    

    在调试 CMake 构建时您可以做的另一件有用的事情是打印出运行编译器的命令:

    make VERBOSE=1
    

    然后您可以获取命令并手动调整它们以使其正常工作。之后就是修改CMAKE_C_FLAGS/include_directories/link_directories

    【讨论】:

      猜你喜欢
      • 2013-02-17
      • 2017-04-04
      • 2022-08-24
      • 2022-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-06
      • 1970-01-01
      相关资源
      最近更新 更多