【问题标题】:Issue with CMake project buildingCMake项目建设的问题
【发布时间】:2013-11-23 00:47:22
【问题描述】:

我有以下问题。在我的 Ubuntu 上,我尝试构建一个项目并收到以下链接器错误:

/usr/bin/ld:
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../x86_64-linux-gnu/libboost_thread.a(once.o): undefined reference to symbol 'pthread_once@@GLIBC_2.2.5'
/lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO
missing from command line collect2: error: ld returned 1 exit status
make[2]: *** [sunprint] Error 1 make[1]: ***
[CMakeFiles/sunprint.dir/all] Error 2 make: *** [all] Error 2
*** Failure: Exit code 2 ***

我在 ubuntu 13 桌面、GCC 4.8、boost 版本下运行。是 1.54。作为我正在使用的 IDE 是KDevelop。 如果需要,我可以提供有关此问题的任何其他信息,但现在我坚持 这个链接问题。

有什么想法吗? 提前谢谢。

【问题讨论】:

    标签: c++ linux ubuntu gcc cmake


    【解决方案1】:

    add_definitions 只为预处理器添加输入,它甚至在 编译器 开始其业务之前就在起作用,甚至距离链接可执行文件更远,步骤 ld 应该是做。

    您希望 ld 解决链接时依赖关系的是 CMake 命令 target_link_libraries,对于给定的目标,它会在编译后添加一些要链接的库。

    在您的情况下,适当的调用可能如下所示

    target_link_libraries(${PROJECT_NAME} [...] -lpthread [...]) #obviously without the '[...]' and the correct target name
    

    【讨论】:

    • 谢谢!这使得项目构建没有任何其他问题:)
    【解决方案2】:

    我遇到了类似的问题,但mpich。两者:

    target_link_libraries(${PROJECT_NAME} [...] -lmpich [...])
    

    target_link_libraries(${PROJECT_NAME} [...] mpich [...])
    

    工作正常。

    【讨论】:

      猜你喜欢
      • 2016-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多