How to say "gmake" to use a different version of GCC? (Linux)

I have regular gcc on my machine (in / usr / bin / gcc) and the other (newer) is connected when I set up the environment for the specific structure I'm working on.

And I would like to compile the old file that I have / usr / bin / gcc, instead of using the newer.

I need to use the "gmake" command to compile (custom compilation setting).

Without changing PATH, how can I “tell” gmake to use another gcc?

+3
source share
3 answers

from the command line: gmake CC=/usr/bin/gcc

+11
source

Using

make CC=/opt/bin/my-gcc

And make sure you use $ (CC) instead of direct gcc to compile:

foo.o: foo.c
          $(CC) -c foo.c -o foo.o

, gmake CC

+4

In your makefile, define a variable for your preferred compiler.

CC=/usr/bin/gcc

And after your goal, use a variable.

a.o : a.c
    $(CC) ...
+2
source

Source: https://habr.com/ru/post/1789214/


All Articles