Set GCC version for make in shell

24,593

GNU Make manual, 6.10 Variables from the Environment:

Variables in make can come from the environment in which make is run. Every environment variable that make sees when it starts up is transformed into a make variable with the same name and value. However, an explicit assignment in the makefile, or with a command argument, overrides the environment. (If the -e flag is specified, then values from the environment override assignments in the makefile. But this is not recommended practice.)

The recommended practice is to pass these variables on make command line:

$ make CC=gcc-4.4 CPP=g++-4.4 CXX=g++-4.4 LD=g++-4.4

A side note is that CXX is used for compiling C++ code, whereas CPP is for preprocessing. Either the author of the makefile confused CPP with CXX, or the makefile indeed uses CPP for generating dependencies, which has been unnecessary for the last decade or so. See this for more details.

Share:
24,593
Markus L
Author by

Markus L

Myself System Architect Java EE Developer C# Developer C/C++ Developer PostgreSQL / Oracle database analyst Most useful applications Total Commander Eclipse Visual Studio Araxis Merge ACDsee WinAmp

Updated on July 05, 2022

Comments

  • Markus L
    Markus L almost 2 years

    I have two gcc (same applies to g++) versions installed. The newer one is the default one:

    /usr/bin/gcc      # 4.9.2
    /usr/bin/gcc-4.4  # 4.4.7
    

    For my make command I want to use gcc-4.4 / g++-4.4.

    I've tried these three variantes but none seems to work:

    export CC="gcc-4.4"
    export CPP="g++-4.4"
    
    export CC=/usr/bin/gcc-4.4
    export CPP=/usr/bin/g++-4.4
    
    export gcc=/usr/bin/gcc-4.4
    export g++=/usr/bin/g++-4.4
    

    The Makefile defines:

    # Compiler Options
    CC       = gcc
    CPP      = g++
    LD       = g++
    

    The compiler used by the Makefile is still 4.9.2. How can I use 4.4.7?