This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Compiling one shared library on Linux to target all distributions
- From: linux problems <linuxproblems at hotmail dot com>
- To: "libstdc++ at gcc dot gnu dot org" <libstdc++ at gcc dot gnu dot org>
- Date: Wed, 21 May 2014 05:24:32 +0000
- Subject: Compiling one shared library on Linux to target all distributions
- Authentication-results: sourceware.org; auth=none
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.
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
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? Is there another suggested way to create one .so for all Linux distros?