Link against a particular version of libstdc++

Our development machines have libstdc++.so.5 and libstdc++.so.6.

When we build our native code, it uses libstdc++.so.6. Is there anyway I can force it to use libstdc++.so.5 instead ?

[/tmp]$ ldd try
        /usr/lib/libcwait.so (0x00655000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x007cd000)
        libc.so.6 => /lib/tls/libc.so.6 (0x00399000)
        libm.so.6 => /lib/tls/libm.so.6 (0x004c5000)
        libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x007a3000)
        /lib/ld-linux.so.2 (0x0037c000)
[/tmp]$ ls -l /usr/lib/libstdc++*
-rwxr-xr-x  1 root root 258288 Dec 14  2004 /usr/lib/libstdc++-2-libc6.1-1-2.9.0.so
-rwxr-xr-x  1 root root 268428 Dec 14  2004 /usr/lib/libstdc++-3-libc6.2-2-2.10.0.so
lrwxrwxrwx  1 root root     30 Oct 18  2006 /usr/lib/libstdc++-libc6.1-1.so.2 -> libstdc++-2-libc6.1-1-2.9.0.so
lrwxrwxrwx  1 root root     31 Oct 18  2006 /usr/lib/libstdc++-libc6.2-2.so.3 -> libstdc++-3-libc6.2-2-2.10.0.so
lrwxrwxrwx  1 root root     18 Oct 18  2006 /usr/lib/libstdc++.so.5 -> libstdc++.so.5.0.7
-rwxr-xr-x  1 root root 744136 Dec  1  2004 /usr/lib/libstdc++.so.5.0.7
lrwxrwxrwx  1 root root     18 Oct 18  2006 /usr/lib/libstdc++.so.6 -> libstdc++.so.6.0.3
-rwxr-xr-x  1 root root 807680 Dec 20  2005 /usr/lib/libstdc++.so.6.0.3

Here the machine/gcc details

[/tmp]$ gcc --version
gcc (GCC) 3.4.5 20051201 (Red Hat 3.4.5-2)
Copyright (C) 2004 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.

[/tmp]$ uname -a
Linux staci21 2.6.9-34.0.1.0.11.ELsmp #1 SMP Thu Oct 26 14:26:54 PDT 2006 i686 i686 i386 GNU/Linux
[/tmp]$ 

Thanks.

How are you compiling this? Can't you directly specify the name(full path) of the lib file to link to in your compile command?

We put in the -lstdc++ flag. I have searched for a flag which allows me a flag like

-x/path/to/libstdc++.so.5

Are you using gcc? I have gcc 3.4.6 installed and the '-x' option is used to specify what language to treat the input files as.

What I meant is, that you should compile like this:

gcc -otry /path/to/libstdc++.so.5 try.cpp

I tried this with some C code:

cc -oserver /lib/libsocket.so.1 -lnsl server.c

It compiles without any problems.

two answers...

  1. list the explicit path on the link line, ld will extract the SONAME and use it.

  2. use -lstdc++.5

With suggestion 1, it does get compiled with libstdc++.so.5. It also gets compiled with libstdc++.so.6. See this

ldd setup | grep libstd
        libstdc++.so.5 => /usr/lib/libstdc++.so.5 (0x03ff5000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x007cd000)

I also get a warning.

/usr/bin/ld: warning: libstdc++.so.6, needed by /usr/lib/qt-3.3/lib/libqt-mt.so, may conflict with libstdc++.so.5

I wonder could this be the reason why libstdc++.so.6 is also required ?

With suggestion 2, I get the error

/usr/bin/ld: cannot find -lstdc++.5
collect2: ld returned 1 exit status
make: *** [setup] Error 1