pthread.h 的 undefined reference to `pthread_create'

在编译中要加 -lpthread或-pthread参数(不同版本的gcc可能不一样,man gcc可以查阅对应参数)。

例如:在加了头文件#include <pthread.h>之后执行 pthread.c文件,需要使用如下命令:

    gcc -lpthread -o thread thread.c

    gcc -pthread -o thread thread.c

这种情况类似于<math.h>的使用,需在编译时加 -m 参数。

原文地址:https://www.cnblogs.com/bittorrent/p/5985372.html