9

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?

Jonas
130k103 gold badges329 silver badges408 bronze badges
asked Nov 11, 2010 at 7:43

1 Answer 1

21

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

answered Nov 11, 2010 at 7:49
Sign up to request clarification or add additional context in comments.

2 Comments

If the package the OP is compiling uses a configure script, then setting CC as an exported shell variable before running configure should set it in the generated Makefile.
make CC=/opt/gcc-4.0.1/bin/gcc works perfectly and is the easier solution ! Thanks

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.