1

I am trying to build a SFML project with g++ 5. Unfortunately there is a bug in g++ 5 which prevents the link stage of a build using some SFML libraries from passing successfully.

This link has more details on the bug.

http://en.sfml-dev.org/forums/index.php?topic=20394.0

I couldn't figure out how to use the workaround. Appending -lgcc_s -lgcc to the my build command line didn't work.

I would like to know how to install a fallback version of gcc/g++. Let's specifically take version 4.9 as an example, as I am fairly confident this version will work.

Can this be done in a way in which I can still retain gcc/g++ 5 as my "default" or "main" c/c++ compiler? I am assuming I then call g++-4.9 rather than just g++ to compile a program using version 4.9?

Can this be done, and if so how? Are there any potential problems (breaking my system) with this?

4
  • What version of Ubuntu are you using? if it is 16.04, then you can install g++-4.9 direct from the universe repository. You can either call g++-4.9 explicitly or set a variable during compilation e.g. make 'CXX=/usr/bin/g++-4.9', depending on your software's build system. Commented Aug 2, 2016 at 16:35
  • @steeldriver 16.04 is the version I'm using. Thanks - should be easy then? Commented Aug 2, 2016 at 16:36
  • Yes easy, just enable universe then install + use Commented Aug 2, 2016 at 16:50
  • @steeldriver Universe must have been enabled already because it just worked on my system - thanks, this answered the question i asked (but unfortunately didn't solve the problem, hmm) Commented Aug 2, 2016 at 18:11

1 Answer 1

0

You could always download and build the version of GCC you want, then add a script in /usr/bin/ to run it. There's other ways of doing this which involves editing the PATH but I am not 100% sure on the details so... script it is I guess. (note: gcc-x.y.z is the version you want to use, IE: gcc-4.9.0. Don't type gcc-x.y.z it will not work)

This article from the OSDev wiki goes over installing a version of GCC (it says newest but you can do any version you want when you download from the ftp mirror).

Start by downloading the version of GCC you want from here.

Extract it into $HOME/src. You should have a gcc folder or something like that in $HOME/src.

Go to gcc-x.y.z/ and execute contrib/download_prerequisites This should get the correct versions of the dependencies you need.

Now decide if you want this for just you or globally. If you're just using this you can install it in $HOME/opt/ or globally /usr/local/gcc-x.y.z (I don't think it really matters since we will be placing a script in /usr/bin but don't quote me on that one)

Now, execute export PREFIX="$HOME/opt/gcc-x.y.z (or the /usr/local/gcc-x.y.z if you're using that as your prefix)

Now, according to the OSDev wiki you want to do

cd $HOME/src

If you wish to build these packages as part of gcc: mv gmp-x.y.z gcc-x.y.z/gmp mv mpfr-x.y.z gcc-x.y.z/mpfr mv mpc-x.y.z gcc-x.y.z/mpc

Then:

mkdir build-gcc cd build-gcc ../gcc-x.y.z/configure --prefix="$PREFIX" --disable-nls --enable-languages=c,c++ make make install

Now you can find it in $PREFIX/gcc-x.y.z (should be the $HOME/opt/cross or /usr/local/gcc-x.y.z)

now make a file in /usr/bin called gcc-4.9 (and g++-4.9). In the script, add

#!/bin/sh

and

$HOME/opt/gcc-x.y.z/gcc "$@"

This will pass all the arguments from the command to this version of gcc. (psst, do the same for the g++ script as well)

Test it out to see if it works. Also if anyone has suggestions in the comments please tell me because I probably made a mistake somewhere.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .