【发布时间】:2016-10-03 02:15:19
【问题描述】:
我在使用 pthread 编译一段简单的代码时遇到以下链接错误。
The system i am working on is x86_64 (gcc (GCC) 4.4.7 20120313 (Red Hat 4.4.7-11) and am compiling as -
gcc -lpthread ~/temp/temp.cpp -lrt -L"/usr/lib/x86_64-redhat-linux5E/lib64/".
很明显问题出在 pthread 库上。所以我有两个问题。
第一季度。将 x64 pthread 库与 x86 代码一起使用是否可以。 (在这段代码中无关紧要,但在我的使用中确实如此)(我猜不是,但我如何区分 x64 和 x86 库?)
第二季度。我看到 pthread 和 lrt 都存在于 /usr/lib 中,但即使我给出该路径,它也会显示 -lpthread not found。
我在这里缺少什么?感谢您的帮助。
错误:
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x12): undefined reference to `__libc_csu_fini'
/usr/lib/gcc/x86_64-redhat-linux/4.4.7/../../../../lib64/crt1.o: In function `_start':
(.text+0x19): undefined reference to `__libc_csu_init'
/tmp/cc2GQOUf.o:(.eh_frame+0x12): undefined reference to `__gxx_personality_v0'
collect2: ld returned 1 exit status
代码:
#include <stdio.h>
#include <pthread.h>
int main()
{
pthread_t f1_thread;
return 0;
}
【问题讨论】: