How to use 2 different versions of GCC on Linux Ubuntu and force MAKE to use one of them
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
blackLabrador
Updated on July 23, 2022Comments
-
blackLabrador almost 2 years
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 invokegcc -v
I still get the resultgcc version 4.4.5
. To compile my program which come already with a makefile, if I domake
, it's still using the new version of gcc. How could I tellmake
to use the old version? -
caf over 13 yearsIf the package the OP is compiling uses a
configure
script, then settingCC
as an exported shell variable before runningconfigure
should set it in the generatedMakefile
. -
blackLabrador over 13 yearsmake CC=/opt/gcc-4.0.1/bin/gcc works perfectly and is the easier solution ! Thanks