undefined reference to 'pthread_create'

undefined reference to 'pthread_create'
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 选项


猜你喜欢

转载自blog.csdn.net/Dable_cn/article/details/36441937