简体   繁体   中英

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?

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++

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM