【发布时间】:2014-03-21 23:32:38
【问题描述】:
所以我做了一个使用信号量的方法。
我的程序打开
#include <pthread.h>
#include <semaphore.h>
我的make文件是
officeHours: officeHours.c
gcc -o officeHours officeHours.c -lpthread -lrt
编辑:添加 -lrt....没有变化
但是,当我制作它找到的文件时,找不到符号
sem_destroy sem_getvalue sem_init sem_post sem_wait
这是为什么?
编辑:“make officeHours”的输出
cc -o officeHours officeHours.c
"officeHours.c", line 4: warning: invalid white space character in directive
"officeHours.c", line 5: warning: invalid white space character in directive
"officeHours.c", line 41: warning: argument #3 is incompatible with prototype:
prototype: pointer to function(pointer to void) returning pointer to void : "/usr/include/pthread.h", line 197
argument: pointer to void
"officeHours.c", line 68: warning: argument #3 is incompatible with prototype:
prototype: pointer to function(pointer to void) returning pointer to void : "/usr/include/pthread.h", line 197
argument: pointer to void
Undefined symbol first referenced in file
sem_destroy officeHours.o
sem_getvalue officeHours.o
sem_init officeHours.o
sem_post officeHours.o
sem_wait officeHours.o
【问题讨论】:
-
如果您查看 Makefile 输出的第一行,您会发现它正在调用不同的命令:
cc -o officeHours officeHours.c -
嗯.....它为什么要这么做?我的make文件和上面的完全一样
-
另外,如果是这样的话,编译器不会也抱怨 pthread_create 和 pthread_join 因为它们来自 -lpthread