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

 

#include <pthread.h>
#include <stdio.h>

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 即可。

 

 

 


本文转载:CSDN博客