Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing default C compiler in Linux, using SCons

Tags:

c

gcc

scons

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.

like image 288
ereOn Avatar asked May 31 '10 14:05

ereOn


People also ask

Does Linux have C compiler by default?

No. A C-compiler (any C-compiler, GCC is just an example, it might just as well be clang/lvm, or something else) is just incredibly handy to have. And not just on a Linux system, but also on BSDs or windows installations.

What C compiler does Linux use?

GCC, or the GNU Compiler Collection, has been around since the 1980s, predating Linux itself. Not only does it compile C programs, but also handles C++, Objective-C, Objective-C++, Fortran, ADA, and Go. A lot of open-source projects still rely on it, including the Linux kernel.

How do I find C compiler in Linux?

If you want to check if the GNU GCC Compilers are install on your system, you can try to check the version of GCC compiler on Linux, or you can use which command to locate gcc or g++ commands . devops@devops-osetc:~$ gcc --version gcc (Ubuntu 5.4. 0-6ubuntu1~16.04. 4) 5.4.


2 Answers

  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'
like image 112
Yktula Avatar answered Oct 13 '22 00:10

Yktula


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!

like image 27
FatalFlaw Avatar answered Oct 13 '22 00:10

FatalFlaw