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?
You need to use the which command to locate c compiler binary called gcc. Usually, it is installed in /usr/bin directory.
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.
DIFFERENCE BETWEEN g++ & gcc g++ is used to compile C++ program. gcc is used to compile C program.
There are multiple ways to achieve what you are looking for:
Setting the environment variable CXX
just for the process that will run make
:
$ CXX=/path-to-your-compiler/g++ make
Exporting the environment variable CXX
in your shell:
$ CXX=/path-to-your-compiler/g++
$ export CXX
$ make
Setting CXX
at make
's command-line:
$ make CXX=/path-to-your-compiler/g++
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++
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With