PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP 未声明(在此函数内第一次使用) 规格严格

用g++ 编译的时候没有问题,但是用gcc 就出现
PTHREAD_ERRORCHECK_MUTEX_INITIALIZER_NP未声明(在此函数内第一次使用) 这样的提示,pthread.h已经包含了,问题出在编译参数上面。

g++ recursion.c -orecursion -lpthread

gcc recursion.c -o recursion -lpthread -D_GNU_SOURCE

gcc 多了一个选项:-D_GNU_SOURCE

对于Linux下的信号量/读写锁文件进行编译,需要在编译选项中指明-D_GNU_SOURCE
means the compiler will use the GNU standard of compilation, the superset of all
other standards under GNU C libraries.

这是网上转载的,其实很简单,看pthread.h里面,存在宏定义,把它定义出来就可以了

原文地址:https://www.cnblogs.com/diyunpeng/p/2381638.html