How to link to a specific library (g ++; libstdc ++. So.5 and libstdc ++. So.6)

A simple question is - can I link the g++ linker to a specific version of the libstdc++ ? I did not find anything useful in the gcc / g++ man page, and other issues here.

Here's the situation - my application uses a specific shared library created using libstdc++.so.5 , and I want to install and use it on RHEL5 . Therefore, when I try to create an application on an RHEL5 machine, I received a warning:

 warning: libstdc++.so.5, needed by ..the_shared_library_.. may conflict with libstdc++.so.6 

Installing compat-libstdc++ rpm did not help, the program crashes from the std::string destructor due to inability. So, on this RHEL5 machine, I have this:

 [ root@xxx ]# ll /usr/lib/libstd* -rwxr-xr-x 1 root root 259532 Aug 21 2006 /usr/lib/libstdc++-3-libc6.2-2-2.10.0.so lrwxrwxrwx 1 root root 31 Jul 28 19:35 /usr/lib/libstdc++-libc6.2-2.so.3 -> libstdc++-3-libc6.2-2-2.10.0.so lrwxrwxrwx 1 root root 18 Aug 24 15:08 /usr/lib/libstdc++.so.5 -> libstdc++.so.5.0.7 -rwxr-xr-x 1 root root 733456 Aug 21 2006 /usr/lib/libstdc++.so.5.0.7 

and when i do

 [ root@xxxx ]# ldd my_exe libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00333000) ... libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x00ddf000) 

which is bad since I know its undefined behavior: /

So, is there a way to create my executable using only libstdc++.so.5 ? (uninstalling libstdc++.so.6 not an option due to many reasons. Static binding is also not an option).

Thanks a lot!

+4
source share
1 answer

Here is the ABI version table ; the default value for the -fabi-version switch changed from 1 to 2, while g ++ introduced libstdC ++. so.6 s 3.4. This means that to bind to the old libstdc ++ library you need

  • find and use equivalent C ++ headers instead of those included in your compiler
  • recompile all your code (and any other C ++ libraries that you use) with -fabi-version=1

Otherwise, you risk ABI incompatibility. I cannot tell you exactly what changes have occurred, but in general it is best to try to save all the C ++ code that you compiled with the same version of the compiler.

Assuming you don't want to try to hack things like this, I think you have two options:

  • ask your shared library vendor to recompile the library with your version of GCC for you. This may not be trivial, since g ++ 3.4 introduced a new, more stringent C ++ parser.
  • ask your provider which version of g ++ they used to compile the library in the first place, and use this version to compile your own code. RH can provide the compat-gcc compiler as well as libstdc ++ - I can't remember. However, you will also need lower-level versions for all other C ++ and OS supported libraries, so it may be easiest to compile on a virtual machine with an older version of Red Hat that has the correct compiler.
+5
source

All Articles