当gcc一个多线程应用程序的时候,虽然已经include <pthread.h>
但仍需要在编译中要加 -lpthread参数,gcc thread.c -o thread -lpthread ,thread.c为你些的源文件
不然就会出现类似undefined reference to 'pthread_create'这样的问题。
原因分析:
pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。