简体   繁体   English

Boost Asio中的链接错误

[英]linking error in boost asio

I am getting below linking error while compiling a simple piece of code using pthread. 使用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/".

Its evident that the problem is with pthread library. 很明显,问题出在pthread库。 So i have two questions. 所以我有两个问题。

Q1. Q1。 is it fine to use x64 pthread libs with x86 code. 将x64 pthread库与x86代码一起使用是否很好? (In this piece of code it doesnt matter but it does in my usage) (I guess its not but how might i differentiate between x64 and x86 libs?) (在这段代码中没关系,但是在我的用法中确实有关系)(我猜不是,但是我如何区分x64和x86库?)

Q2. Q2。 i see pthread and lrt both are present at /usr/lib but even if i give that path it says -lpthread not found. 我看到pthread和lrt都存在于/ usr / lib中,但是即使我给出该路径,它也会显示-lpthread not found。

What am i missing here? 我在这里想念什么? Thanks for your help. 谢谢你的帮助。

Error : 错误:

/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

Code : 代码:

#include <stdio.h>
#include <pthread.h>

int main()
{
  pthread_t f1_thread;
 return 0;
}

In compilation phase,compiler can use gcc or g++ ,but g++ will call gcc command automatically.But in link phase,linker can use g++ or gcc -lstdc++ .Because the gcc command cannot link with the libraries that be used by c++ program automatically, so usually use g++ to complete the link. 在编译阶段,编译器可以使用gccg++ ,但是g++会自动调用gcc命令。但是在链接阶段,链接器可以使用g++gcc -lstdc++ 。由于gcc命令无法与c ++程序自动使用的库链接,因此通常使用g++完成链接。

So the command g++ -g -lpthread ~/temp/temp.cpp -o temp should be ok. 因此,命令g++ -g -lpthread ~/temp/temp.cpp -o temp应该可以。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM