I have a Makefile for a C program that has the declaration
CC?=gcc Changing it to
CC?=g++ does NOT make it compile with g++. Changing it to
CC=g++ DOES make it use g++.
So I wonder what the ?= operator does? My guess is that it looks at a environment variable to decide which compiler to use and if it's not set then use gcc? Anyone who can clear this up?
?= indicates to set the KDIR variable only if it's not set/doesn't have a value. For example: KDIR ?= "foo" KDIR ?= "bar" test: echo $(KDIR)
c=.o} means, take the variable value ${SRCS} , which is a string composed of words separated by spaces, and for each word, replace the suffix .
The simple answer is that %.o is a target that matches any file ending in .o. "%.o: %. c" means that any file ending in .o depends on the same filename ending in . c to be present.
This is a CMake Environment Variable. Its initial value is taken from the calling process environment. Preferred executable for compiling C language files. Will only be used by CMake on the first configuration to determine C compiler, after which the value for CC is stored in the cache as CMAKE_C_COMPILER .
From http://www.gnu.org/software/make/manual/make.html:
There is another assignment operator for variables, `?='. This is called a conditional variable assignment operator, because it only has an effect if the variable is not yet defined. This statement:
FOO ?= baris exactly equivalent to this (see The origin Function):
ifeq ($(origin FOO), undefined) FOO = bar endif
Probably CC is already defined as gcc, so CC ?= g++ won't override the existing gcc.
The ?= operator sets the variable only if it isn't already set: info make → * Using Variables → * Setting.
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