您的位置:首页 > 其它

UMIP程序中碰到的问题

2010-09-26 01:17 267 查看

问题一

‘PTHREAD_MUTEX_FAST_NP’ undeclared (first use in this function)

查看/usr/include/pthread.h line.59

59 #ifdef __USE_GNU

60 /* For compatibility. */

61 , PTHREAD_MUTEX_FAST_NP = PTHREAD_MUTEX_TIMED_NP

62 #endif

63 };

解决方法一是添加宏定义#define __USE_GNU 1,二是使用PTHREAD_MUTEX_TIMED_NP,

三是在Makefile文件中加入-D_GNU_SOURCE

4 test_pthread.o : debug.h

5 cc -D_GNU_SOURCE -c test_pthread.c

问题二

test_pthread.o: In function `main':

test_pthread.c:(.text+0x31): undefined reference to `pthread_mutexattr_init'

test_pthread.c:(.text+0x45): undefined reference to `pthread_mutexattr_settype'

test_pthread.c:(.text+0x99): undefined reference to `pthread_create'

添加头文件#include <pthread.h>

在Makefile中链接多线程库-lpthread

debug.o: In function `dbg_strdate':

debug.c:(.text+0x4d): undefined reference to `clock_gettime'

添加头文件#include <time.h>

在Makefile中添加链接库-lrt,因为在librt中实现了clock_gettime函数

2 test : $(objects)
3 cc -o test $(objects) -lpthread -lrt

问题三

lizhipeng@pp:~/test/pmip$ make

cc -o pmip -lpthread -lrt

/usr/lib/gcc/i486-linux-gnu/4.4.3/../../../../lib/crt1.o: In function `_start':

(.text+0x18): undefined reference to `main'

collect2: ld returned 1 exit status

make: *** [pmip] Error 1

检查了很久,发现是Makefile写错了,漏写了一个字母b

1 ojects = main.o tqueue.o debug.o
2 pmip : $(objects)
3 cc -O2 -Wall -o pmip $(objects) -lpthread -lrt

ojects应该改为objects
以后这种问题一定要小心,查找错误时也应该明确方向
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐