undefined reference to `pthread_create‘ 解决办法,编译提示pthread_create未定义解决办法,Linux系统编译提示pthread_ 函数未定义解决办法

 pthread线程操作函数库不是Linux系统默认的库,编译时需要指定使用线程库libpthread.a,所以在使用pthread_create创建线程时,在gcc编译时要加-lpthread参数选项。

root@ubuntu:/home/forlinuxsmb/threads# gcc threadid.c
/tmp/cc2ZWjnD.o: In function `main':
threadid.c:(.text+0x3c6): undefined reference to `pthread_create'
collect2: ld returned 1 exit status


如:
root@ubuntu:/home/forlinuxsmb/threads# gcc threadid.c -lpthread
root@ubuntu:/home/forlinuxsmb/threads# ./a.out

root@ubuntu:/home/forlinuxsmb/threads# gcc threadid.c -lpthread -o threadid
root@ubuntu:/home/forlinuxsmb/threads# ./threadid

猜你喜欢

转载自blog.csdn.net/rabbit200808/article/details/107436104