Issues with two versions of libstdC++.so

I'm facing an issue in which my program is using a custom library (say, libxyz.so) which is compiled using libstdc++.so.5 and the system I'm using this library to create an executable from my program, has libstdc++so.6 as well as libstdc++.so.5; both available under /usr/lib directory.

There are multiple compilers available with the system (i.e gcc, g++34 and g++ version 4.*, IBM xlc).

When I compile my program, the resultant binary has to link libxyz.so (which has libstdc++.so.5 already) and based on further symbols need, it has to use libstdc++.so, but it by default links with libstdc++.so.6 and these two versions of libstdc++ gets its way into my executable.

This clearly shows up the cross links when done ldd on my executable. The program crashes when run. Because some classes are not compatible in libstdc++.so between versions 5 and 6.

Being C++ program, still I compiled and linked with gcc itself which is by default linking only with libstdc++.so.5 but had to use -fno-use-cxa_exception_ptr as flag to suppress the undefined reference issue on exception handling code. This made my binary having uniform links with libstdc++.so.5 through out and the program runs well. But this is just a work around and not an acceptable solution.

Is there a way, in which we can make g++ (or even g++34) to link explicitly with a particular library version overriding the default behavior to link with the latest version?

In that case I would prefer to link with libstdc++.so.5 through out.

Thanks a lot in advance for your suggestions / insight and for your precious time of course.

Regards,
PraveenK

---------- Post updated at 12:25 AM ---------- Previous update was at 12:05 AM ----------

It would also be great, if you suggest on editing the gcc/g++ compile specs. However that again is not a very open option if this is not an user account specific changes. Although I have the root access but would not be allowed to make system configuration changes.

I'm confused. Is there no way to link your library code on each platform? That way it will always run wherever it is ported to. It is not clear to me if this is what you are asking.

You seem to want to be able to link your code where ever it resides. You have two choices: link statically on the home machine, or compile to object code - ex: libfoo.a, on the home machine, then link a new PIC code library on each platform. Assuming your code links correctly against various installation of c++.

Static linking kind of defeats the purpose of a library. But it will work.

You cannot depend on version libstsdc++5 or 6 or whatever being available when you port your code. Lugging dynamic code from box to box is not always feasible. As you found out.

1 Like

Hi Jim,
Thanks for your response to my query.
No, I don't have the option to re-compile the library (say libxyz.so) and this is a black box to me being a 3rd party library package already compiled for my platform. This library using an older version of libstdc++.so.5; however my platform currently has libstdc++.so.6 (as well as libstdc++.so.5 co-existing) and the g++ compiler by default uses libstdc++.so.6 to link any code compiled on my platform (however gcc picks up libstdc++.so.5 by default).

Hence compiling a program which also uses libxyz.so through g++ is creating an undesired scenario by linking to some function calls using libstdc++.so.6 (by default) and some function calls residing into the library libxyz.so also is linked to my program as their API is called but those API's function definition has already linked to libstdc++.so.5

Hence I get an executable which has function calls linking to two versions of libstdc++.so. This creates problem while execution and dumps code.

All I need is a way to override the library selection behavior by the compiler/linker so that I can choose to link to a particular version of my choice at the link time.

I essentially want to link all my programs to libstdc++.so.5 and NOT with libstdc++.so.6

I tried "ldconfig" utility to change behavior by following (as a root):

# ldconfig -p > ldconf.conf

The file "ldconf.conf" thus produced had libstdc++.so.6 listed just prior to libstdc++.so.5; so I swapped their positions and did the following:

# ldconfig -f ldconf.conf

I received errors like (didn't work):

# ldconfig -f ldconf.conf
...
...
ldconfig: > /usr/lib64/libtag.so.1 is not a known library type
ldconfig: > /usr/lib64/libsysfs.so.2 is not a known library type
ldconfig: > /usr/lib64/libstdc++.so.5 is not a known library type
ldconfig: > /usr/lib/libstdc++.so.5 is not a known library type
ldconfig: > /usr/lib64/libstdc++.so.6 is not a known library type
ldconfig: > /usr/lib/libstdc++.so.6 is not a known library type
ldconfig: > /usr/lib/libstdc++-libc6.2-2.so.3 is not a known library type
ldconfig: > /usr/lib64/libstartup-notification-1.so.0 is not a known library type
ldconfig: > /usr/lib64/libsss_idmap.so.0 is not a known library type
ldconfig: > /usr/lib64/libssl3.so is not a known library type
...
...
ldconfig: > /lib64/ld64.so.1 is not a known library type
ldconfig: > /lib/ld.so.1 is not a known library type
ldconfig: Can't create temporary cache file /etc/ld.so.cache~: Permission denied

Have you tired putting libstdc++.so.5 in a different place and using LD_LIBRARY_PATH to point to that location?

Yes already tried. Even I created a soft link inside my present working directory to point to libstdc++.so.5; didn't work.

Did like this:

$ ln -s /usr/lib/libstdc++.so.5 libstdc++.so
$ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.

I also did

 $ strace g++ simpleTrialProgram.cpp -o someExe 

Just to understand how g++ is finding libraries by default and found it looks to certain number of pre-defined directories one by one on a decreasing priority (including reaching a level to look inside /usr/lib folder).

But why g++ is choosing version 6 when the same /usr/lib folder has version 5 where as gcc chooses version 5 when the same directory has higher version 6 available to it.

There must be somewhere the information g++ is driving out to select a particular version over other, when multiple available.

LD_LIBRARY_PATH doesn't work that way... Give it an absolute path, and only one path.

Sure Corona, I'll try his again tomorrow morning and update you.

---------- Post updated at 11:34 AM ---------- Previous update was at 12:03 AM ----------

Hi Corona,
Didn't work for me or did I do some mistakes? Here is the combined output for a sample program compilation:

[root@p208n11 tr]# ll
total 148
-rwxr-xr-x 1 root root 11055 Feb 18 02:21 a.out
-rw-r--r-- 1 root root   108 Feb 18 02:23 cppProg.cpp
-rw-r--r-- 1 root root 59512 Feb 18 04:11 ldLib.log
-rw-r--r-- 1 root root 59512 Feb 18 04:18 ldLib.log.2
lrwxrwxrwx 1 root root    23 Feb 18 04:23 libstdc++.so -> /usr/lib/libstdc++.so.5
-rwxr-xr-x 1 root root 11055 Feb 18 02:22 og++34Comp
-rw-r--r-- 1 root root     0 Feb 20 00:14 strace.log
[root@p208n11 tr]# strace g++34 libstdc++.so cppProg.cpp -o trcpp2 2> strace.log
[root@p208n11 tr]# ll
total 196
-rwxr-xr-x 1 root root 11055 Feb 18 02:21 a.out
-rw-r--r-- 1 root root   108 Feb 18 02:23 cppProg.cpp
-rw-r--r-- 1 root root 59512 Feb 18 04:11 ldLib.log
-rw-r--r-- 1 root root 59512 Feb 18 04:18 ldLib.log.2
lrwxrwxrwx 1 root root    23 Feb 18 04:23 libstdc++.so -> /usr/lib/libstdc++.so.5
-rwxr-xr-x 1 root root 11055 Feb 18 02:22 og++34Comp
-rw-r--r-- 1 root root 47687 Feb 20 00:15 strace.log
[root@p208n11 tr]# cat cppProg.cpp
#include <iostream.h>
#include <strings.h>

int
main (){

std::cout<< "Hellow world" << endl;

return 0;

}
[root@p208n11 tr]#
[root@p208n11 tr]# g++34 lstdc++.so cppProg.cpp -o trcpp2
g++34: lstdc++.so: No such file or directory
In file included from /usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/iostream.h:31,
                 from cppProg.cpp:1:
/usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
[root@p208n11 tr]# ll
total 172
-rwxr-xr-x 1 root root 11055 Feb 18 02:21 a.out
-rw-r--r-- 1 root root   108 Feb 18 02:23 cppProg.cpp
-rw-r--r-- 1 root root 59512 Feb 18 04:11 ldLib.log
-rw-r--r-- 1 root root 59512 Feb 18 04:18 ldLib.log.2
lrwxrwxrwx 1 root root    23 Feb 18 04:23 libstdc++.so -> /usr/lib/libstdc++.so.5
-rwxr-xr-x 1 root root 11055 Feb 18 02:22 og++34Comp
-rw-r--r-- 1 root root 21159 Feb 20 00:19 strace.log
[root@p208n11 tr]# g++34 lstdc++ cppProg.cpp -o trcpp2
g++34: lstdc++: No such file or directory
In file included from /usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/iostream.h:31,
                 from cppProg.cpp:1:
/usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
[root@p208n11 tr]# ll
total 172
-rwxr-xr-x 1 root root 11055 Feb 18 02:21 a.out
-rw-r--r-- 1 root root   108 Feb 18 02:23 cppProg.cpp
-rw-r--r-- 1 root root 59512 Feb 18 04:11 ldLib.log
-rw-r--r-- 1 root root 59512 Feb 18 04:18 ldLib.log.2
lrwxrwxrwx 1 root root    23 Feb 18 04:23 libstdc++.so -> /usr/lib/libstdc++.so.5
-rwxr-xr-x 1 root root 11055 Feb 18 02:22 og++34Comp
-rw-r--r-- 1 root root 21159 Feb 20 00:19 strace.log
[root@p208n11 tr]# g++34 lstdc cppProg.cpp -o trcpp2
g++34: lstdc: No such file or directory
In file included from /usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/iostream.h:31,
                 from cppProg.cpp:1:
/usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
[root@p208n11 tr]# ll
total 172
-rwxr-xr-x 1 root root 11055 Feb 18 02:21 a.out
-rw-r--r-- 1 root root   108 Feb 18 02:23 cppProg.cpp
-rw-r--r-- 1 root root 59512 Feb 18 04:11 ldLib.log
-rw-r--r-- 1 root root 59512 Feb 18 04:18 ldLib.log.2
lrwxrwxrwx 1 root root    23 Feb 18 04:23 libstdc++.so -> /usr/lib/libstdc++.so.5
-rwxr-xr-x 1 root root 11055 Feb 18 02:22 og++34Comp
-rw-r--r-- 1 root root 21159 Feb 20 00:19 strace.log
[root@p208n11 tr]# g++34 cppProg.cpp -o trcpp2
In file included from /usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/iostream.h:31,
                 from cppProg.cpp:1:
/usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
[root@p208n11 tr]# ll
total 184
-rwxr-xr-x 1 root root 11055 Feb 18 02:21 a.out
-rw-r--r-- 1 root root   108 Feb 18 02:23 cppProg.cpp
-rw-r--r-- 1 root root 59512 Feb 18 04:11 ldLib.log
-rw-r--r-- 1 root root 59512 Feb 18 04:18 ldLib.log.2
lrwxrwxrwx 1 root root    23 Feb 18 04:23 libstdc++.so -> /usr/lib/libstdc++.so.5
-rwxr-xr-x 1 root root 11055 Feb 18 02:22 og++34Comp
-rw-r--r-- 1 root root 21159 Feb 20 00:19 strace.log
-rwxr-xr-x 1 root root 11055 Feb 20 00:20 trcpp2
[root@p208n11 tr]# ldd trcpp2
        linux-vdso64.so.1 =>  (0x00000fff8c800000)
        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000008027d00000)
        libm.so.6 => /lib64/power6/libm.so.6 (0x0000008026290000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000008026d40000)
        libc.so.6 => /lib64/power6/libc.so.6 (0x0000008026030000)
        /lib64/ld64.so.1 (0x0000000042b20000)
[root@p208n11 tr]# echo $LD_LIBRARY_PATH
/root/tr
[root@p208n11 tr]# pwd
/root/tr
[root@p208n11 tr]# g++34 lstdc++.so cppProg.cpp -o trcpp3
g++34: lstdc++.so: No such file or directory
In file included from /usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/iostream.h:31,
                 from cppProg.cpp:1:
/usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
[root@p208n11 tr]# g++34 libstdc++.so cppProg.cpp -o trcpp3
In file included from /usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/iostream.h:31,
                 from cppProg.cpp:1:
/usr/lib/gcc/ppc64-redhat-linux/3.4.6/../../../../include/c++/3.4.6/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the <X> header for the <X.h> header for C++ includes, or <iostream> instead of the deprecated header <iostream.h>. To disable this warning use -Wno-deprecated.
libstdc++.so: could not read symbols: File in wrong format
collect2: ld returned 1 exit status
[root@p208n11 tr]# ll
total 184
-rwxr-xr-x 1 root root 11055 Feb 18 02:21 a.out
-rw-r--r-- 1 root root   108 Feb 18 02:23 cppProg.cpp
-rw-r--r-- 1 root root 59512 Feb 18 04:11 ldLib.log
-rw-r--r-- 1 root root 59512 Feb 18 04:18 ldLib.log.2
lrwxrwxrwx 1 root root    23 Feb 18 04:23 libstdc++.so -> /usr/lib/libstdc++.so.5
-rwxr-xr-x 1 root root 11055 Feb 18 02:22 og++34Comp
-rw-r--r-- 1 root root 21159 Feb 20 00:19 strace.log
-rwxr-xr-x 1 root root 11055 Feb 20 00:20 trcpp2
[root@p208n11 tr]#

I also ran strace over compilation and the strace log files are attached for your reference. Like:

[root@p208n11 tr]# strace g++34 cppProg.cpp -o trcpp2 2> strace.log
[root@p208n11 tr]# strace g++34 libstdc++.so cppProg.cpp -o trcpp2 2> strace.x.log

Also tried running ldconfig utility, like:

[root@p208n11 tr]# ldconfig -p > ldLib.log

Created a copy of file ldLib.log as ldLib.log.2 and edited the file ldLib.log.2 to swap positions of libstdc++.so.6 and libstdc++.so.5 and ran the config utility again, like:

[root@p208n11 tr]# ldconfig -f ldLib.log.2 2> ldconfig-f.log

Got errors logged into file ldconfig-f.log for reference and is attached herewith this post.

Here are few other information, which might be of help:

[root@p208n11 tr]# uname -a
Linux p208n11.pbm.ihost.com 2.6.32-358.el6.ppc64 #1 SMP Tue Jan 29 11:43:27 EST 2013 ppc64 ppc64 ppc64 GNU/Linux
[root@p208n11 tr]# cat /etc/redhat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
[root@p208n11 tr]# g++34 -v
Reading specs from /usr/lib/gcc/ppc64-redhat-linux/3.4.6/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --disable-libunwind-exceptions --enable-languages=c,c++,f77 --disable-libgcj --host=ppc64-redhat-linux
Thread model: posix
gcc version 3.4.6 20060404 (Red Hat 3.4.6-19.el6)
[root@p208n11 tr]# /usr/bin/ldd --version
ldd (GNU libc) 2.12
Copyright (C) 2010 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.

Added .txt as suffix to all the attachments as .log is not into the valid list of files. They all are text essentially, without "\n".

The earlier "Format error" produced due to my mistakes due to using 32-bit libstdc++.so.5 . Corrected that to link the 64-bit libstdc++.so.5 with a simplest program to print a "Hello World" message but even there the link happened for not just the version 5 which I provided but also linked some symbols to version 6 by default.

[root@p208n11 tr]# g++34 cppProg.cpp libstdc++.so.5 -o tr96

[root@p208n11 tr]# ldd tr96
        linux-vdso64.so.1 =>  (0x00000fff8d000000)
        libstdc++.so.5 => /root/tr/libstdc++.so.5 (0x00000fff8cec0000)
        libstdc++.so.6 => /usr/lib64/libstdc++.so.6 (0x0000008027d00000)
        libm.so.6 => /lib64/power6/libm.so.6 (0x0000008026290000)
        libgcc_s.so.1 => /lib64/libgcc_s.so.1 (0x0000008026d40000)
        libc.so.6 => /lib64/power6/libc.so.6 (0x0000008026030000)
        /lib64/ld64.so.1 (0x000000005d120000)
[root@p208n11 tr]# ./tr96
Hellow world
[root@p208n11 tr]# cat cppProg.cpp
#include <iostream.h>
#include <strings.h>

int
main (){

std::cout<< "Hellow world" << endl;

return 0;

}
[root@p208n11 tr]# echo $LD_LIBRARY_PATH
/root/tr
[root@p208n11 tr]# pwd
/root/tr
[root@p208n11 tr]# ll libstdc*
lrwxrwxrwx 1 root root 25 Feb 20 05:11 libstdc++.so.5 -> /usr/lib64/libstdc++.so.5