Chinaunix首页 | 论坛 | 博客
  • 博客访问: 324771
  • 博文数量: 50
  • 博客积分: 961
  • 博客等级: 准尉
  • 技术积分: 495
  • 用 户 组: 普通用户
  • 注册时间: 2011-04-07 08:30
文章分类

全部博文(50)

文章存档

2015年(2)

2014年(1)

2013年(4)

2012年(18)

2011年(25)

分类: LINUX

2011-09-11 09:35:24

最近线程编程对项目模块进行验证,照着GUN/Linux编程指南,写了三个线程,书写了Makefile,结果编译链接时,出现如下错误:
minicnc_test.c:(.text+0xa8): undefined reference to `pthread_create'
minicnc_test.c:(.text+0xc0): undefined reference to `pthread_create'
minicnc_test.c:(.text+0xd8): undefined reference to `pthread_create'

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

问题解决:
 
(1)在Makefile中,要加 -lpthread参数
如下所示:
 comm_mcu_task.o: comm_mcu_task.c
             $(CROSS) -c comm_mcu_task.c -lpthread
(2)在源文件中,不要忘了加上头文件#include
阅读(1048) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~