Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set GCC path in makefile

Whenever I am building my package it uses /usr/bin/g++ (system compiler). I want to build my package with C++11 constructs. I have tried -std=c++11 option but with system compiler it says unrecognized option. I want to build my package from a different gcc compiler which will get downloaded as part of my package dependency.

So, how can I specify the location of gcc compiler in Makefile?

like image 301
Pavan Tiwari Avatar asked Apr 28 '18 12:04

Pavan Tiwari


People also ask

What is the path for gcc?

You need to use the which command to locate c compiler binary called gcc. Usually, it is installed in /usr/bin directory.

What is Cflags in Makefile?

CFLAGS and CXXFLAGS are either the name of environment variables or of Makefile variables that can be set to specify additional switches to be passed to a compiler in the process of building computer software.

What is difference between G ++ and gcc?

DIFFERENCE BETWEEN g++ & gcc g++ is used to compile C++ program. gcc is used to compile C program.


1 Answers

There are multiple ways to achieve what you are looking for:

  1. Setting the environment variable CXX just for the process that will run make:

    $ CXX=/path-to-your-compiler/g++ make
    
  2. Exporting the environment variable CXX in your shell:

    $ CXX=/path-to-your-compiler/g++
    $ export CXX
    $ make
    
  3. Setting CXX at make's command-line:

    $ make CXX=/path-to-your-compiler/g++
    
  4. Inside your makefile:

    CXX := /path-to-your-compiler/g++
    

Note that setting the variable at make's command line overrides the other values, and variables set inside the makefile override the ones obtained from the environment (unless the command-line option -e or --environment-overrides is provided).

Inside your makefile, you can still override any value set by other means by using the override directive:

override CXX := /path-to-your-compiler/g++
like image 59
ネロク・ゴ Avatar answered Oct 12 '22 00:10

ネロク・ゴ