我已经写了一些代码,它在linux下编译得很好,但是在Solaris上我有一些编译错误。我用gcc test_compile.c -o tes -pthreads
来编译。无法在Solaris下使用信号编译代码?
#include <semaphore.h>
int main(){
sem_t semaphore;
sem_init(&semaphore, 0, 0);
return 0;
}
给我
itchy:~/edu/sysprog> gcc test_compile.c -o tes -pthreads
Undefined first referenced
symbol in file
sem_init /var/tmp//ccUiSK6A.o
ld: fatal: Symbol referencing errors. No output written to tes
我不知道发生了什么事情。我尝试用sema_init
替换sem_init
,并编译(看到在线的某处)。但是这意味着我必须通过我的整个代码并用sema替换sem。没有更简单的解决方案吗?它是什么意思?
你得到一个编译时错误,但它是不是编译器错误。不幸的是,“编译”这个词已经被用来表示“构建一个可执行文件”,但是两者不一样。你的问题是链接器。 –