Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I target older linux with newer gcc/clang? C++

Tags:

c++

linux

glibc

Right now I compile my C++ software on a certain old version of linux (SLED 10) using the provided gcc and it can run on most newer versions as they have a newer glibc. Problem is, that old gcc doesn't support C++11 and I'd really like to use the new features.

Now I have some ideas, but I'm sure others have the same need. What's actually worked for you?

Ideas:

  1. Build on a newer system, static link to newer glibc. (Not possible, right?)
  2. Build on a newer system, compile and link against an older glibc.
  3. Build on an older system using an updated gcc, link against older glibc.
  4. Build on a newer system, dynamic link to newer glibc, set RPath and provide our glibc with installer.

As a bonus, my software also support plugins and has an SDK. I'd really prefer that my customers could compile against my libraries without a huge hassle.

Thanks in advance. Ideas welcome, proven solutions preferred.

like image 599
David Avatar asked Jul 03 '12 21:07

David


People also ask

Is Linux compiled with GCC or clang?

GCC supports more language extensions and more assembly language features than Clang and LLVM. GCC is still the only option for compiling the Linux kernel.

Does clang optimize better than GCC?

Clang is much faster and uses far less memory than GCC. Clang aims to provide extremely clear and concise diagnostics (error and warning messages), and includes support for expressive diagnostics. GCC's warnings are sometimes acceptable, but are often confusing and it does not support expressive diagnostics.

Is clang compatible with GCC?

Yes, for C code Clang and GCC are compatible (they both use the GNU Toolchain for linking, in fact.) You just have to make sure that you tell clang to create compiled objects and not intermediate bitcode objects. C ABI is well-defined, so the only issue is storage format.

Does clang use Libgcc?

Clang supports use of either LLVM's libc++ or GCC's libstdc++ implementation of the C++ standard library.


1 Answers

Build with the newer gcc. Either install the new compiler on the old machine or comile on your new machine and install the necessary dynamic libraries on the old machine.

Note that multiple versions of libc (and also libstdc++) are supported on a single machine since they are typically versioned (i.e. libc.so.5, libc.so.6, etc)

like image 192
Anon Mail Avatar answered Oct 13 '22 15:10

Anon Mail