在Linux上编译和链接不同版本的gcc [英] Compiling and linking with a different versions of gcc on linux

查看:72
本文介绍了在Linux上编译和链接不同版本的gcc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我计划使用gcc 4.7.1编译静态库(mylib.a).我想利用C ++ 11的优势,因此使用-std = c ++ 11.我在其中编译该lib的平台是带有glibc-2.8的x86_64 SLES 11.

I am planning to compile a static library (mylib.a) with gcc 4.7.1. I want to take the advantages of C++11, so -std=c++11 is used. The platform, where I compile this lib is x86_64 SLES 11 with glibc-2.8.

然后,我想使用旧版代码将旧版平台上的此静态库链接,因此我必须使用gcc 4.1.2链接和编译旧版代码.因此,在我的库头文件中,我将不使用任何C ++ 11特定的代码.我还将链接来自gcc.4.7.1的libstdc ++.a.我要链接mylib.a,libstdc ++.a(gcc4.7.1)和旧版目标文件的平台是带有glibc-2.4的x86_64 SLES 10.

Then I want to link this static library on a legacy platform with a legacy code, therefore I must use gcc 4.1.2 for linking and compiling the legacy code. So in my library headers I will not use any C++11 specific code. Also I will link libstdc++.a from gcc.4.7.1. The platform, where I want to link mylib.a, libstdc++.a(gcc4.7.1) and the legacy object files is x86_64 SLES 10 with glibc-2.4.

我在mylib.a中用一些虚拟的C ++ 11代码(std :: async())尝试了所有这些混乱,并且可以正常工作.我认为这仅是由于ELF的要求才有可能.我是在正确思考,还是ELF与它无关?如果mylib.a包含一些真正复杂的逻辑,我应该期待什么样的错误?

I tried all of this mess with some dummy C++11 code (std::async()) in mylib.a and it worked. I think this is possible only becuase of the ELF requiriements. Am I thinking correctly, or ELF has nothing to do with it? What kind of errors should I expect if mylib.a will contain some truly complex logic?

推荐答案

Linux具有C ++应用程序二进制接口(ABI),已经存在了一段时间.这意味着在Linux上跨编译器的调用约定和名称修改是固定的.因此,只要这些库兼容,您就应该能够使用不同的编译器(或同一编译器的不同版本)进行编译,并且具有正确可靠地链接在一起的代码.

Linux has a C++ Application Binary Interface (ABI), which has been around for a while. This means that the calling conventions and name mangling across compilers on Linux is fixed. Therefore, as long as the libraries are compatible, you should be able to compiler with different compilers (or different versions of the same compiler) and have code which correctly and reliably links together.

ELF要求本身不完全是 ...

Not entirely the ELF requirements per se...

这篇关于在Linux上编译和链接不同版本的gcc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆