/tmp/cckp7gaI.o(.text+0x70): In function `main':
: undefined reference to `pthread_create'
collect2: ld returned 1 exit status
可以看出是在ld的时候系统无法找到pthread_create函数。也就是说编译器在link得时候找不到其中的一个使用库的函数。
由于pthread
库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,在编译中要加 -lpthread参数
文章详细介绍了在Linux环境下链接pthread库时遇到'undefined reference to `pthread_create''错误的原因及解决方案,重点阐述了如何通过在编译时添加-lpthread参数来解决该问题,并解释了pthread库在多线程编程中的重要性。
2148

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



