在程序中没有用到pthread,但是在编译的时候出现了以下错误:
undefined reference to symbol 'pthread_create@@GLIBC_2.2.5'
//lib/x86_64-linux-gnu/libpthread.so.0: error adding symbols: DSO missing from command line
后来想起来自己在程序中用到了C++11中的线程std::thread,个人猜测C++11在封装线程std::thread时应当是使用到了pthread,所以linux下在程序中使用到std::thread,应当添加一下信息:
由于pthread库不是Linux系统默认的库,连接时需要使用库libpthread.a,所以在使用pthread_create创建线程时,在编译中要加-lpthread参数:
gcc pthread.c -lpthread -o pthread
下面是codeblocks的修改:
设置>>编译器设置>>全局编译器设置>>链接器设置:
左侧链接库加入: /usr/lib/x86_64-linux-gnu/libpthread.a (通过locate libpthread.a确定的)
右侧其他链接器选项加入: -lpthread
如果你的libpthread.a不在lib64下可以用如下命令查找:
$ locate libpthread.a
![](https://i-blog.csdnimg.cn/blog_migrate/befdbe039e19489aed380de54161724c.png)