I'm using the last version of Ubuntu which come with the gcc 4.4.5 version. I need to recompile a program that was not written by me and that can be only compiled with an older version of gcc like the 4.0. I managed to configure this older version and used a prefix during the install process so that my old gcc version is in the /opt/gcc-4.0.1/bin. I have tried to create a symlink using ln -s /opt/gcc-4.0.1/bin/gcc gcc
. But when I invoke gcc -v
I still get the result gcc version 4.4.5
. To compile my program which come already with a makefile, if I do make
, it's still using the new version of gcc. How could I tell make
to use the old version?
Make uses some standard variables in order to determine which tools to use, the C-compiler variable is called "CC". You can set the CC variable, either directly in your Makefile
CC=/opt/gcc-4.0.1/bin/gcc
which is fine if you're working alone on it, or everyone has the same setup. Or you can pass it on the command line like so:
make CC=/opt/gcc-4.0.1/bin/gcc
the third option is set /opt/gcc-4.0.1/bin before everything else in your path (which is why it doesn't work for you, the current directory isn't in the path, so the symlink you put there will not be considered when searching)
export PATH=/opt/gcc-4.0.1/bin:$PATH
For completeness, in your symlink solution, you'd have to invoke ./gcc
to get the right gcc instance, but IMHO this is probably not the best solution.
HTH