Take the 2-minute tour ×

Can I install an older version of gcc/g++ (4.1.3) on the latest Ubuntu (which comes with 4.4.3) and use it to compile a .so which should run on CentOS? The binary compiled with the Ubuntu version of gcc fails to load on CentOS because of missing imports (GLIB_2_11, ...). I need C++ (including exceptions), so I can't just statically link against glibc, which I already tried.

Can I install the older gcc without removing the newer one? How do I go about the libs required by the older gcc?

I'm currently developing code in CentOS, but it's such a pain to use. I really want to move to an Ubuntu desktop.

share|improve this question
What's wrong with developing on an Ubuntu desktop and building your final binaries (and occasional integration builds) on a CentOS machine (maybe even inside a virtual machine). –  Joachim Sauer May 4 '10 at 11:48
I already use VMs. The CentOS VM currently boots up in 5 min, and one VM is already enough for a 4GB RAM laptop. –  Adal May 4 '10 at 13:50
Try disabling SELinux, if you haven't already. I've seen that cause excessive slowdown within VMs. –  Josh Kelley May 4 '10 at 14:44
add comment

1 Answer

up vote 3 down vote accepted

g++-4.1 is available for Ubuntu; just run apt-get install g++-4.1 then run g++-4.1 instead of g++. However, simply using an older compiler may not fix all of your library issues.

Like Joachim Sauer said, your best bet is to do your development on Ubuntu then do the final compilation on CentOS.

Even though you're using C++, static linking should still be an option. (However, you're much better off compiling on CentOS and using dynamic linking.)

Edit: A virtual machine is the most straightforward way to build on CentOS, but if you want to avoid the memory and CPU overhead of running a VM and don't care about differences between Ubuntu's and CentOS's kernel, then you can create a subdirectory containing a CentOS or Fedora filesystem and chroot do that to do your builds. This blog posting has details.

share|improve this answer
Apparently statically linking against libstdc++ on Linux is more complicated that it would seem: trilithium.com/johan/2005/06/static-libstdc –  Adal May 4 '10 at 13:56
add comment

Your Answer


