2

I am working on a Project, which uses classes from the C++11 standard, on a Fedora 18 machine and want to deploy it on a Centos 6.4 server.

I was able to resolve all loader errors except for the libc and libc++ versions, which are GLIBC_2.11, GLIBCXX_3.4.15 and on my Fedora machine GLIBC_2.14 and at least GLIBCXX_3.4.17 respectively.

Is it possible to tell the compiler to compile/link for the server versions or older compatible versions of the libraries?

When i run ldd executable i get

./executable: /lib64/libc.so.6: version `GLIBC_2.14' not found (required by ./executable)
./executable: /usr/lib64/libstdc++.so.6: version `GLIBCXX_3.4.15' not found (required by ./executable)

Thanks in advance!

Philipp Gebhard
  • 301
  • 3
  • 11
  • [This question](http://stackoverflow.com/questions/2728552/link-to-a-different-libc-file) already deals with libc, it shouldn't be too hard to extend it to libstdc++. – syam May 14 '13 at 13:05
  • I copied the needed shared objects from my developer machine into a libs folder and added **-Xlinker -rpath=libs/ -Xlinker -Ilibs/ld.so** the the **CXXFLAGS** and **LFLAGS** in the **Makefile**. Then i copied this folder and the executable to the server and i get other linker errors regarding Qt. At least some progress :-) – Philipp Gebhard May 14 '13 at 13:46
  • @syam: Thanks! I was able to get the program running :-) Just copied all needed shared libraries into this lib folder and deployed everything to the server. – Philipp Gebhard May 14 '13 at 14:47

1 Answers1

5

Instead of manually copying libraries to a separate directory you could set up a chroot contaiing the CentOS build env, using mock and the epel-6-x86_64 config.

Use yum in the mock chroot to install the packages you want (e.g. Qt) and build in there, that will ensure the code only uses the CentOS 6 libs that are installed in the chroot, not the rest of the packages on your Fedora OS.

Update:

When I'm using a mock chroot for building GCC I do this:

# only need these steps once to setup the chroot
mock -r fedora-19-x86_64 --init
mock -r fedora-19-x86_64 --install yum
mock -r fedora-19-x86_64 --shell 'mkdir -p /builddir/gcc/src /builddir/gcc/build'
su -c 'mount --bind $PATH_TO_GCC_SOURCES /var/lib/mock/fedora-19-x86_64/root/builddir/gcc/src'
# enter root password
mock -r fedora-19-x86_64 --shell
# now in chroot
yum install gmp-devel mpfr-devel libmpc-devel flex autogen
su - mockbuild
cd gcc/build
../src/configure --prefix=/builddir/gcc/install ... etc. ...

For your purpose you'd replace fedora-19 with epel-6

The bind mount means I don't need to have the GCC sources in the chroot, I can use the existing copy in my normal filesystem. See http://gcc.gnu.org/wiki/InstallingGCC for info on building GCC

Once you install GCC in the chroot you can use it to build your own programs then package them up for CentOS.

To go back into the chroot again later:

mock -r fedora-19-x86_64 --shell
su - mockbuild
Jonathan Wakely
  • 166,810
  • 27
  • 341
  • 521
  • What about missing functions in `glibc`? Since we use C++11 the `glibc` version from CentOS might not support that. – Philipp Gebhard May 15 '13 at 13:35
  • 1
    The mock chroot would use the same glibc as the CentOS machine, so the executable wouldn't depend on anything in the newer glibc anyway. However, you said "Is it possible to tell the compiler to compile/link for the server versions or older compatible versions of the libraries?" but that contradicts wanting to use the newer libraries. Either you link to the older libs without C++11 features or you link to the newer ones with C++11 features, you can't have both! – Jonathan Wakely May 15 '13 at 14:48
  • If you need the C++11 features then you'll need the newer libs on the CentOS box, or you could install the newer GCC in the mock chroot, so it uses the CentOS glibc, then you could use `-static-libstdcxx` to link statically to the newer libstdc++. That way your executable will not depend on `libstdc++.so` and will only depend on the older glibc, which is present on the CentOS box – Jonathan Wakely May 15 '13 at 14:49
  • I've added some more info to help you get started – Jonathan Wakely May 16 '13 at 09:09
  • Thank you very much for your help! I think we have now a good compile environment for our server application. – Philipp Gebhard May 17 '13 at 12:10