15

On my Linux platform, I have several versions of gcc.

Under usr/bin I have:

  • gcc34
  • gcc44
  • gcc

Here are some outputs:

$ gcc --version
gcc (GCC) 4.1.2 20080704 (Red Hat 4.1.2-48)

$ gcc44 --version
gcc44 (GCC) 4.4.0 20090514 (Red Hat 4.4.0-6)

I need to use the 4.4 version of gcc however the default seems to the 4.1 one.

I there a way to replace /usr/bin/gcc and make gcc44 the default compiler not using a symlink to /usr/bin/gcc44 ?

The reason why I can't use a symlink is because my code will have to be shipped in a RPM package using mock. mock creates a minimal linux installation from scratch and just install the specified dependencies before compiling my code in it. I cannot customize this "minimal installation".

Ideally, the perfect solution would be to install an official RPM package that replaces gcc with gcc44 as the default compiler. Is there such a package ? Is this even possible/good ?

Additional information

I have to use SCons (a make alternative) and it doesn't let me specify the binary to use for gcc.

I will also accept any answer that will tell me how to specify the gcc binary in my SConstruct file.

usr1234567
  • 21,601
  • 16
  • 108
  • 128
ereOn
  • 53,676
  • 39
  • 161
  • 238
  • What linux distribution? Some have methods of selecting the default versions – bdbaddog Feb 14 '18 at 13:37
  • If you need to use an entirely different compiler, not only a different version, see this question: https://stackoverflow.com/q/13161690/3052438 – Piotr Siupa May 14 '22 at 10:13

2 Answers2

14
  1. One way is to compile and install gcc from source.

  2. See http://old.nabble.com/Choosing-compiler-td4675207.html

From that:

env = Environment()
env.Replace(CC = "my_cc_compiler")

Or, as per the answer to this question,

env['CC'] = 'gcc44'
Community
  • 1
  • 1
Yktula
  • 14,179
  • 14
  • 48
  • 71
  • 2
    cc=env['gcc44'] is incorrect.. env['CC']='gcc44' is correct. (though you likely need to do so for CXX, SHCC, SHCXX, SHLINK, LINK, etc.. See manpage for what those are all used for. – bdbaddog May 26 '16 at 18:53
8

This is a long way in the past now, but I just thought I'd add the solution I found, which doesn't require changing the SConscript file. It was useful for me as I need to build v8 under centos 5, so possibly it may be useful for someone else too.

CC=gcc44 CXX=g++44 scons

That's it!

FatalFlaw
  • 1,077
  • 11
  • 19
  • 14
    Note that scons (unlike e.g. a typical autotools project) does not by default allow you to override the CC/CXX variables via the environment. The SConscript have to be specifically created to do so. – nos Nov 15 '13 at 21:17
  • yes, to set CC and CXX scons should be called like, eg.: scons CXX=clang++ CC=clang target – MariuszW Aug 03 '22 at 10:26