Fire Lancer
Fire Lancer

Reputation: 30145

What is needed to use a newer version of GCC than the platform provides

I am looking at the potential to use a newer version of GCC (e.g. 5.2) than is provided by some of the platforms that I need to support (GCC 4.1) as I would like to at least have C++11 features, and maybe even some C++14 things. I just provide an executable program, not static or shared libraries that I expect users of the platform to be able to link with.

I was able to compile GCC 5.2 and Boost 1.59 (the only lib with a C++ API I am using currently) and get it working with the so's for those placed alongside the executable and adding $ORIGIN to RPATH on a test system which has 4.4.

But I am unclear on what else I need to do this fully and ensure everything is correct/safe. e.g. I noticed libc, libm, libpthread, etc. are not part of the GCC build, and it still uses the system version, as with many other third party libraries (e.g. zlib, libpng, etc.). Do I need to rebuild and distribute all those to be safe? Is their a standard set of rules to tell?

Also wondering if I should statically link some things and again what the rules are? e.g. just using "-static" fails because it goes looking for a static pthread that I don't have on that system (and I assume other system-provided libraries). Ideally I want to keep the size of my package down.

Upvotes: 3

Views: 2116

Answers (5)

ARG
ARG

Reputation: 241

I think there is an easier way then compiling GCC yourself. [Unfortunately I figured that out after compiling it from source a number of time :) ]

For example in Ubuntu there is a PPA for precompiled GCC versions which are not there yet in the official repository.

sudo add-apt-repository ppa:ubuntu-toolchain-r/test

sudo apt-get update

sudo apt-get install gcc-5 g++-5
sudo update-alternatives 
sudo update-alternatives --remove-all gcc
sudo update-alternatives --remove-all g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-5 20
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-5 20
sudo update-alternatives --config gcc
sudo update-alternatives --config g++

Upvotes: 1

Jeff Hammond
Jeff Hammond

Reputation: 5642

Follow directions to build from source. Revise your question if you face a problem.

Upvotes: 1

Maxim Egorushkin
Maxim Egorushkin

Reputation: 136296

But I am unclear on what else I need to do this fully and ensure everything is correct/safe. e.g. I noticed libc, libm, libpthread, etc. are not part of the GCC build, and it still uses the system version, as with many other third party libraries (e.g. zlib, libpng, etc.). Do I need to rebuild and distribute all those to be safe? Is their a standard set of rules to tell?

Run ldd on your executables and shared libraries to make sure that it loads libstdc++ and libgcc_s from the correct location, if you link them dynamically. These are the only two dependencies normally required to run your applications built with g++.

Normally, you do not need to provide your own versions of libraries with C interface, unless your application requires newer versions with incompatible APIs.

Upvotes: 3

Jonathan Wakely
Jonathan Wakely

Reputation: 171313

I noticed libc, libm, libpthread, etc. are not part of the GCC build, and it still uses the system version, as with many other third party libraries (e.g. zlib, libpng, etc.). Do I need to rebuild and distribute all those to be safe?

No. If you build GCC on the system you want to deploy to then the GCC binaries and shared libraries will depend on the system versions of libc, libpthread etc.

If you then use that GCC to compile your software, and deploy the new libstc++.so.6 alongside your software (using $ORIGIN so it will be found), then it will still use the system versions of those libraries. Which is exactly what should happen and what you want to happen. Rebuilding them would achieve nothing and simply mean you have more libraries to deploy alongside your software.

Upvotes: 2

Recent GCC compilers have a lot of dependencies.

On some distributions, you could ask for them : on Debian or related you might aptitude build-dep gcc (provided you have deb-src: in your /etc/apt/sources.list) which would dowload the build dependencies of the system's gcc (which might have a lot of common dependencies with the latest GCC).

Otherwise, GCC source code contain a contrib/download_prerequisites script which should be handy.

Read carefully the GCC building procedure. Don't forget to compile it outside of the source tree. You might want to pass --program-suffix=-5-mine to its configure

Of course you'll also need to build all the other software needed to compile (or to cross-compile) your code with the newly built GCC, including binutils, gdb, and perhaps a C library

Alternatively use a chroot (or some container à la docker) to install a newer Linux system...

Upvotes: 2

Related Questions