views:

163

answers:

1

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.

+2  A: 

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.

Josh Kelley
Apparently statically linking against libstdc++ on Linux is more complicated that it would seem: http://www.trilithium.com/johan/2005/06/static-libstdc/
Adal