【问题标题】:linking error in boost asioboost asio中的链接错误
【发布时间】: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;
}

【问题讨论】:

    标签: c++ linux pthreads


    【解决方案1】:

    在编译阶段,编译器可以使用gccg++,但g++会自动调用gcc命令。但在链接阶段,链接器可以使用g++gcc -lstdc++。因为@987654327 @命令不能自动链接c++程序使用的库,所以一般使用g++完成链接。

    所以g++ -g -lpthread ~/temp/temp.cpp -o temp这个命令应该没问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-10-15
      相关资源
      最近更新 更多