undefined reference to 'pthread_create'
undefined reference to 'pthread_join'
问题原因:
undefined reference to 'pthread_join'
问题原因:
pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
解决方法:
在编译中要加 -lpthread选项
gcc thread.c -o thread -lpthread
thread.c为你些的源文件,不要忘了加上头文件#include<pthread.h>
如果分布编译连接程序的话,在连接时加上 -lpthread 选项
本文针对在使用pthread库时遇到的未定义引用错误进行了详细的解析,并提供了具体的解决方案,包括如何正确地链接pthread库。
1655

被折叠的 条评论
为什么被折叠?



