分类:
2010-10-11 22:15:26
‘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
在Makefile中链接多线程库-lpthread
debug.o: In function `dbg_strdate':
debug.c:(.text+0x4d): undefined reference to `clock_gettime'
添加头文件#include
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