当前位置: 代码迷 >> 综合 >> undefined reference to `pthread_create‘ 解决办法,编译提示pthread_create未定义解决办法,Linux系统编译提示pthread_ 函数未定义解决办法
  详细解决方案

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

热度:23   发布时间:2023-12-06 04:11:05.0

 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.outroot@ubuntu:/home/forlinuxsmb/threads# gcc threadid.c -lpthread -o threadid
root@ubuntu:/home/forlinuxsmb/threads# ./threadid

 

 

 

  相关解决方案