undefined reference to symbol 'pthread_create@@GLIBC_2.2.5' 的修改方法

时间:2022-10-20 09:40:20

在编译DSO代码的时候会如下这样的问题:

undefined reference to symbol 'pthread_create@@GLIBC_2.2.5' 的修改方法

检查DSO,在程序中没有用到pthread,但是在编译的时候却出现此类问题。仔细想了想了一下,在程序中用到了C++11中的线程std::thread,个人猜测C++11在封装线程std::thread时应当是使用到了pthread,pthread不是linux下的默认的库,也就是在链接的时候,无法找到phread库中线程函数的入口地址,于是链接会失败。

解决方法:

最简单的就是,打开CMakeLists.txt ,在所有用到boost_thread 的后面加上 -pthread,如下图,保存并重新编译,发现已经解决。

undefined reference to symbol 'pthread_create@@GLIBC_2.2.5' 的修改方法

若未解决问题,可参考下列内容:

1.https://blog.csdn.net/hust_superman/article/details/37655891

2. https://www.cnblogs.com/yxysuanfa/p/7019725.html

3.https://blog.csdn.net/csdn_zyp2015/article/details/73087318