1

I am writing to ask about how to choose the version of gcc during compiling. In my machine, I believe there are several version of gcc installed. Because the command 'gcc -v' returns 'gcc version 6.4.0 (GCC)', while command 'cc' returns 'gcc version 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)'. I know the 'cc' is actually linked to the gcc compiler. And in the makefile, 'CC ?= gcc' should be the command to link cc to gcc.

Thus, is that means the gcc 4.4.7 is always be used when I compiling? Please, how should I change the cc or the makefile to make it link to the newer gcc version? btw, I don't have the permission to use 'sudo' command.

edit: Thanks for your replying. The output of type -a cc is 'cc is /usr/bin/cc' and another output is 'gcc is /util/bin/gcc gcc is /usr/bin/gcc' The upper path is the gcc 6.4 and the lower one is older version.

  • Please edit your question and add the output of type -a cc and type -a gcc. – terdon Mar 17 '18 at 14:27
1

CC in your makefile is just the variable. You can specify any compiler or executable in your system.

Find direct path of your "newer" gcc and put it on CC={Path} and compiling should be ok.

| improve this answer | |
0

The line

CC ?= gcc

in the Makefile means "if the variable CC isn't already set, set it to gcc".

Later in the Makefile, the compiler listed in the CC variable will be used to compile C language files (CC is a standard variable for the C compiler).

If gcc is the compiler you want to use, you don't have to change anything.

If you want to use another compiler, such as clang or gcc-7 or something else completely, you do not have to change the Makefile. Instead, just say

make CC=clang

on the command line (where clang may be just the compiler executable name, or its complete path if it's not available in your own $PATH).

To use ccache (a "compiler cache") with e.g. clang,

make CC='ccache clang'

Since the Makefile tests whether the CC variable is set before setting it to gcc, the above mentioned way is the best way to invoke make with a different compiler. If it had set the value of CC unconditionally, then you would have had to edit the Makefile.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.