Chinaunix首页 | 论坛 | 博客
  • 博客访问: 151927
  • 博文数量: 34
  • 博客积分: 2010
  • 博客等级: 大尉
  • 技术积分: 346
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-19 09:53
文章分类

全部博文(34)

文章存档

2011年(1)

2009年(33)

我的朋友

分类: C/C++

2009-05-31 11:40:41

由于是Linux新手,所以现在才开始接触线程编程,照着GUN/Linux编程指南中的一个例子输入编译,结果出现如下错误:
undefined reference to 'pthread_create'
undefined reference to 'pthread_join'

问题原因:
    pthread 库不是 Linux 系统默认的库,连接时需要使用静态库 libpthread.a,所以在使用pthread_create()创建线程,以及调用 pthread_atfork()函数建立fork处理程序时,需要链接该库。

问题解决:
    在编译中要加 -lpthread参数
    gcc thread.c -o thread -lpthread
    thread.c为你些的源文件,不要忘了加上头文件#include
阅读(774) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~