【发布时间】:2011-11-07 11:06:14
【问题描述】:
我编写了一些在 linux 下编译良好的代码,但在 Solaris 上我得到了一些编译错误。我使用gcc test_compile.c -o tes -pthreads编译。
#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 并编译(在网上某处看到)。但是,这意味着我必须检查整个代码并将 sem 替换为 sema。没有更简单的解决方案吗?它的真正含义是什么?
【问题讨论】:
-
您收到构建时错误,但这不是编译器错误。不幸的是,“编译”一词已被用来表示“构建可执行文件”,但两者并不相同。您的问题出在链接器上。
标签: c solaris linker-errors semaphore build-error