This is the mail archive of the
mailing list for the libstdc++ project.
Re: Compiling one shared library on Linux to target all distributions
- From: Jonathan Wakely <jwakely at redhat dot com>
- To: linux problems <linuxproblems at hotmail dot com>
- Cc: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 21 May 2014 09:47:16 +0100
- Subject: Re: Compiling one shared library on Linux to target all distributions
- Authentication-results: sourceware.org; auth=none
- References: <BAY180-W54C778A8A093DE082F873CB13C0 at phx dot gbl>
On 21/05/14 05:24 +0000, linux problems wrote:
We want to create one shared library (.so) to target all distributions, including old ones. The code is written in C++ and uses C++11 features, so the compiler must be at least gcc 4.7.
We noticed that if we compile our code on a Linux machine with gcc 4.7.2 installed (e.g., Ubuntu 12.10) then the .so produced has âversion 1 (GNU/Linux)â while on older os (e.g., CentOS 5.6) the version is âversion 1 (SYSV)â â and libraries with the GNU/Linux newer version cannot be used on older os.
So we tried the approach of installing gcc 4.7 on the CentOS 5.6 machine, compile our code with this compiler and statically link with libstdc++ (-static-libstdc++) â this produced an .so that was usable on every linux we found.
It might work for your current code, but there's no guarantee your
approach will produce a library that is usable on distros older than
And this worked fine for 32-bit. However, when we followed the same approach on a 64-bit os (CentOS) this failed with the error that the existing libstdc++.a we tried to link to was compiled without âfPIC.
So we tried to compile the gcc 4.7.2 sources with the ââwith-picâ option, but we couldnât link to the new libstdc++.a â the error is:
/opt/centos/devtoolset-1.1/root/usr/libexec/gcc/x86_64-CentOS-linux/4.7.2/ld: /usr/local/lib/libFoo.so: version node not found for symbol _ZNSs7_M_copyEPcPKcm@GLIBCXX_3.4
/opt/centos/devtoolset-1.1/root/usr/libexec/gcc/x86_64-CentOS-linux/4.7.2/ld: failed to set dynamic section sizes: Bad value
collect2: error: ld returned 1 exit status
This looks like https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54482
so might be fixed in GCC 4.7.3 (but I'm not sure)
We googled up that compiling libstdc++ with âfPIC may be problematic, but why does it work for 32-bit and not for 64-bit os?
PIC is implemented differently for x86 and x86_64, because 64-bit mode
has built-in support for it.