Makefile 说变量是空的,但它不是
Makefile says that variable is empty but it's not
我正在尝试创建包含以下内容的 makefile:
$(CXX)=g++
$(SRC)=../src
$(INCL)=../include
all: cpu ram temperature swap statusshooter
$(CXX) main.cpp cpu.o ram.o temperature.o swap.o statusshooter.o -o main.o -I$(INCL) -Ofast -Wall -lyaml-cpp -lglog -lpqxx -lpq
cpu:
$(CXX) -c $(SRC)/CCpu.cpp -o cpu.o -Ofast -Wall
ram:
$(CXX) -c $(SRC)/CRam.cpp -o ram.o -Ofast -Wall
temperature:
$(CXX) -c $(SRC)/CTemperature.cpp -o temperature.o -Ofast -Wall
swap:
$(CXX) -c $(SRC)/CSwap.cpp -o swap.o -Ofast -Wall
statusshooter:
$(CXX) -c $(SRC)/CStatusShooter.cpp -o statusshooter.o -Ofast -Wall
使用以下命令执行该 makefile:
make CXX=g++-4.7
抛出以下错误:
makefile:2: *** empty variable name. Stop.
如何解决?
要为变量赋值,请写入 var=...
,而不是 $var=...
,因此,在您的情况下,
CXX=g++
等
语法 $(CXX)
用于评估 make 变量,而不是分配给它。你要
CXX = g++
SRC = ../src
INCL = ../include
[...]
我正在尝试创建包含以下内容的 makefile:
$(CXX)=g++
$(SRC)=../src
$(INCL)=../include
all: cpu ram temperature swap statusshooter
$(CXX) main.cpp cpu.o ram.o temperature.o swap.o statusshooter.o -o main.o -I$(INCL) -Ofast -Wall -lyaml-cpp -lglog -lpqxx -lpq
cpu:
$(CXX) -c $(SRC)/CCpu.cpp -o cpu.o -Ofast -Wall
ram:
$(CXX) -c $(SRC)/CRam.cpp -o ram.o -Ofast -Wall
temperature:
$(CXX) -c $(SRC)/CTemperature.cpp -o temperature.o -Ofast -Wall
swap:
$(CXX) -c $(SRC)/CSwap.cpp -o swap.o -Ofast -Wall
statusshooter:
$(CXX) -c $(SRC)/CStatusShooter.cpp -o statusshooter.o -Ofast -Wall
使用以下命令执行该 makefile:
make CXX=g++-4.7
抛出以下错误:
makefile:2: *** empty variable name. Stop.
如何解决?
要为变量赋值,请写入 var=...
,而不是 $var=...
,因此,在您的情况下,
CXX=g++
等
语法 $(CXX)
用于评估 make 变量,而不是分配给它。你要
CXX = g++
SRC = ../src
INCL = ../include
[...]