UMIP程序中碰到的问题

问题一

‘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
以后这种问题一定要小心,查找错误时也应该明确方向

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值