在eclipse中编译时出现报错:
undefined reference to 'pthread_create'
undefined reference to 'pthread_join'
问题原因:
pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
解决方法:
1.手动执行gcc,并把pthread库链接进去
gcc thread.c -o thread -lpthread
thread.c为你些的源文件,不要忘了加上头文件#include
2 .
c/c++ build-> setting ->gcc complier
c/c++ build-> setting ->gcc linker
在command 下边All option中 加入 -l pthread 就好了,但是你会发现加不上
undefined reference to 'pthread_create'
undefined reference to 'pthread_join'
问题原因:
pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。
解决方法:
1.手动执行gcc,并把pthread库链接进去
gcc thread.c -o thread -lpthread
thread.c为你些的源文件,不要忘了加上头文件#include
2 .
c/c++ build-> setting ->gcc complier
c/c++ build-> setting ->gcc linker
在command 下边All option中 加入 -l pthread 就好了,但是你会发现加不上
但是可以在以下的子选项中 把参数 -l pthread 加进去。如图: