2

anyone who knows how to make gcc instead of cc the default complier of 'make'?

for example I have a source code xyz.c and in my Makefile I type:

CFLAGS=-Wall -g

all: xyz

and then on the terminal when I execute make xyz, and it outputs

cc -Wall -g xyc.c -o xyz

How can I make gcc it's default compiler?

Raptor
  • 53,206
  • 45
  • 230
  • 366
segfault
  • 70
  • 1
  • 6
  • 2
    cc is just an abstract name for the underlying system compiler. Chances are that it is mapping to `gcc` already. – Martin Konecny Jun 05 '14 at 03:37
  • see if [this](http://stackoverflow.com/questions/7832892/how-to-change-the-default-gcc-compiler-in-ubuntu) helps. – Raptor Jun 05 '14 at 03:39
  • See [Variables Used by Implicit Rules](http://www.gnu.org/software/make/manual/html_node/Implicit-Variables.html) – lurker Jun 05 '14 at 03:40
  • @Martin Konecny. Thanks it works. I also found out in my linux machine cc is just a symbolic link for gcc. Thanks alot. – segfault Jun 05 '14 at 03:46

1 Answers1

4

Usually you do something like:

CC = gcc

And then later something like:

$(CC) -Wall -g xyc.c -o xyz

This allows you to change the compiler at any time by just changing the one line. Note that there are many ways to tell make to compile your program, so unless you provide the full makefile its hard to know if you're using your own rules or implicit ones, etc.

(To make the answer more complete, let me also point to the manual pages reference by @lurker above, which give more information about other variables you might want to set.)

Nathan S.
  • 5,244
  • 3
  • 45
  • 55