Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile for CentOS on Ubuntu

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.

like image 551
Meh Avatar asked May 04 '10 11:05

Meh


People also ask

Is Ubuntu compatible with CentOS?

CentOS uses the rpm package manager, and Ubuntu uses Debian apt. So the packages are not even compatible. Generally, if you want it on CentOS and it doesn't have it already you'll have to build an RPM from source, on another CentOS machine.

Does Ubuntu have GCC?

The gcc package is installed by default on all Ubuntu desktop flavors.


1 Answers

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.

like image 102
Josh Kelley Avatar answered Oct 07 '22 08:10

Josh Kelley