在看《unix环境高级编程》时,试着书中的例子练习pthread_create函数的使用,但是在编译时出现如下的错误:
undefined reference to `pthread_create‘
问题原因:
pthread
库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,需要链接该库。
问题解决:
在编译中要加 -lpthread参数
gcc xxxx.c -o xxxx-lpthread
xxxx.c为你些的源文件, xxxx为目标文件
本文介绍了在使用pthread_create函数创建线程时遇到的编译错误:undefined reference to `pthread_create'。文章详细解释了这一错误的原因在于未链接pthread库,并提供了具体的解决方案,即在编译时添加-lpthread参数。
1641

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



