I am trying to install multiple versions of the g++ compiler for testing purposes.

I would like to be able to install g++ 4.9.3,5.1.0, 5.2.0, and 6.1.0.

I know that I can do

sudo add-apt-repository ppa:ubuntu-toolchain-r/test -y;
sudo apt-get update -qq
sudo apt-get install g++-4.9, g++5.1, g++5.2, g++6

but in my tests, they all end up using the system-installed standard library, which is the g++-4-series standard library. I can tell because when I compile code, the standard library doesn't do some things that the C++11 standard says it should do, for instance, the std::string move constructor is not marked noexcept. But on ubuntu-xenial, which has gcc-6 standard library, it is, and other related issues are solved.

I can see that there are packages named libstdc++-4.8-dev for instance in the ubuntu repository, but when I install the newer compilers they don't seem to use them.

I know also that I can install compilers from source in my home directory, but building them takes so long that I cannot do it within travis-ci unfortunately. In travis-ci, all builds time out after one hour.

Is there an easy way that I can configure the compilers that install from a ppa to use the correct versions of the C++ standard library, i.e., the one that they were released with rather than the system default?

Is there an easy way that I can install a compiler binary with all its associated libs into a folder in my home directory using apt-get that doesn't involve building from source?

I have found these instructions, which say that I can use an -rpath flag or a specs file, or adjust LD_LIBRARY_PATH, but what I'm not sure about is what paths I should be setting. Another issue is that, it's not merely the dynamic linker, the ubuntu-toolchain-r/test compilers seem to be using the system libstdc++ headers also, so I need to correct that somehow.

My current strategy is, just downloading the source-code release tarball and trying to fiddle with the configure flags until I can find a way to build it in < 60 minutes. Once I get it to build once, it is in my "cache" directory so future builds of my project can get the image in < 1 minute.

The "cache" feature is only available when using the ubuntu-precise (12.04 LTS) travis images, so I can't even use trusty here.

My configure line is currently:

${GCC_SRC_DIR}/configure --prefix=${GCC_DIR}  --disable-checking --enable-languages=c,c++ --disable-multilib --disable-bootstrap

I'm doing this mainly based off of this guy's instructions.

There is also an old bug report that mentions it.

The --disable-checking option is not really documented afaict so maybe it is defunct. The --disable-bootstrap option is documented, hopefully it will prevent me from actually building the compiler three times as described here... not sure how likely this is to work though.

I'm using make -j2 --quiet to actually build after that.

Now working with a longer line:

        ${GCC_SRC_DIR}/configure --prefix=${GCC_DIR}  --disable-checking --enable-languages=c,c++ --disable-multilib --disable-bootstrap --disable-libsanitizer --disable-libquadmath --disable-libgomp --disable-libssp --disable-libvtv --disable-libada --enable-version-specific-runtime-libs
  • Please edit your post to include Ubuntu version. ..... ( Ubuntu 14.04 - amd64 ? ) Jul 20, 2016 at 10:25
  • ? Is your version Ubuntu 14.04 - amd64 ? Jul 20, 2016 at 10:34

1 Answer 1


Configuring gcc-5.x : cd build-gcc-5.x/

../gcc-5.3.0/configure --prefix=/usr/local/gcc53 --program-suffix=53 --enable-languages=c,c++ --with-system-zlib --disable-multilib --disable-libstdcxx-pch

( Requires sudo apt install zlib1g-dev, if --with-system-zlib )

About the "60 minutes limit" : You can exit the terminal after say 55 minutes, and just continue later with make.

  • Thanks for the idea! :D I will see if I can execute it correctly.
    – Chris Beck
    Jul 20, 2016 at 10:26
  • So I haven't gotten this idea to work, it's too hard to get it to work in travis because the vms just don't have enough memory to compile gcc it seems. It might also be general instability. But I'm going to mark this as the correct answer anyways, I don't think there was any other possibility.
    – Chris Beck
    Jul 21, 2016 at 14:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.