lundi 29 mai 2017

Can I compile using a specific gcc version like gcc4.1 under gcc 5.4?

I'm currently using gcc (Ubuntu 5.4.0-6ubuntu1~16.04.4) 5.4.0. And there's an existing shared library(probably compiled with some lower version) my executable links against.

Everything's fine until I run my executable and then some runtime error about not finding some symbols in the so rises. I'm pretty sure the headers files are no problem so I checked the specific symbol in the so with objdump and c++filt:

The actual symbol in the so:

CRouterInfo::GetlHost(std::basic_string<char, std::char_traits<char>, std::allocator<char> >&, unsigned short&)

The symbol the dynamic linker is expecting:

CRouterInfo::GetHost(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >&, unsigned short&)

Now it's clear this is because I'm using a newer cpp compiler (cxx11). I then run strings -a xx.so to determine that it's actually compiled under GCC4.1.2.

I have come up with the following idea to deal with it:

  1. recompile the dynamic library using my current gcc version. However I don't have the source code of the so at hand.

  2. Downgrade to gcc4.1.2 and work through everything. Well I'd really not do this for reasons you know why.

  3. Since I'm convinced that other than the symbol decoration differences other aspects of the ABI are no problem for it to run on my current environment (I actually have another 4.1.2 executable that's shifted with the so and works totally fine on my server), I'm tempted to find a way to generate the 4.1.2 symbol that the library desires for my executable code.

Can I do something like this? I noticed a g++ option -fabi-version and tried it with multiple values but still it only generates c++11 symbols.

Any suggestions? Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire