您的位置:首页 > Web前端

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

2015-01-29 22:59 639 查看
      下面, 我们先看一个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 即可。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐