c++ - CMake项目 build 的问题

标签 c++ linux ubuntu gcc cmake

我有以下问题。在我的 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。 如果需要,我可以提供有关此问题的任何其他信息,但现在我坚持 这个链接问题。

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

最佳答案

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

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

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

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

关于c++ - CMake项目 build 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19902595/

相关文章:

linux - 如何检查程序是否在 Windows 上的 Ubuntu 上的 Bash 中运行,而不仅仅是普通的 Ubuntu?

linux - "make check"安装HDF5失败

php - 为什么我的浏览器不加载我的项目 laravel?

c++ - 通过函数指针调用 C++ 成员函数

c++ - 神秘的 HRESULT 错误

c++ - 在 C++ 中,我无法选择特定变量用于用户输入

linux - gzip 文件夹的总大小

c++ - #warning 和 #error 作为宏

linux - 从 root 运行一个脚本,它调用 sudo oracle 中的另一个脚本。如何在不询问 oracle 密码的情况下做到这一点

linux - 如何计算进程 id 的执行指令数,包括子进程