gcc编译出现undefined reference to 'pthread_create'的解决方法

      下面, 我们先看一个linux多线程程序:

#include 
#include 

void* threadFunc(void* p)
{
	while (1)
	{
		printf("a");
	}
 
	return NULL;
}
 
int main ()
{
	pthread_t id;
	pthread_create (&id, NULL, threadFunc, NULL);
 
	while (1)
	{
		printf("b");
	}
 
	return 0;
}
      在linux上执行gcc thread.c,  结果出现编译错误undefined reference to 'pthread_create'。由于pthread库不是标准linux库, 所以出错。 改为gcc thread.c -lpthread 即可。



你可能感兴趣的:(S1:,C/C++,s2:,软件进阶,s2:,Linux杂项)