Code Snippet:
target_test : test.cc $(CXX) $(CPPFLAGS) $(CFLAGS) test.cc
I know that CXX
is a variable (containing the compiler command to call), but I was wondering where this variable comes from. The variable is not defined in the makefile and is not an environment variable. Can anyone explain where the value of CXX
comes from?
CXX is an implicit variable in GNU make. There are others too. Not only that, these implicit variables get used in implicit rules. Here is an extract relating to how CXX is used by an implicit rule: Compiling C++ programs.
This is a CMake Environment Variable. Its initial value is taken from the calling process environment. Preferred executable for compiling CXX language files.
means that the variable CC contains "gcc". You access this variable by doing a $(CC) wherever you need it. Dependencies myprogram: fileA.o fileB.o fileC.o.
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.
Make has several predefined variables among which is CC
. Initially, it is set at cc
which is a symlink to the installed C compiler:
$ readlink -f `which cc` /usr/bin/gcc-4.6
Also:
$ readlink -f `which c++` /usr/bin/g++-4.6
You can change it if you want.
You can use make -p -f /dev/null
to get a list of all implicit rules and variables. I cannot show the output right now because I have a non-standard install and the output is not in English.
CXX is an implicit variable in GNU make. There are others too.
Not only that, these implicit variables get used in implicit rules.
Here is an extract relating to how CXX is used by an implicit rule:
Compiling C++ programs
n.o
is made automatically fromn.cc
,n.cpp
, orn.C
with a recipe of the form$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c
.
We encourage you to use the suffix ‘.cc’ for C++ source files instead of ‘.C’.
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