我正在为我正在使用C++的项目编写一个makefile。我有一个名为tests的目录,其中包含单元测试代码,其中包含使用cxxtest的文件。Makefile不以正确的顺序注册依赖关系
生成文件是:
CC=clang++
CFLAGS=-c -Wall -std=c++11
LDFLAGS= -lsfml-graphics -lsfml-system -lsfml-window
SOURCES=memtest.cpp guitest.cpp
CXXTEST=LTest.h
CXXCPP=$(CXXTEST:.h=.cpp)
CXXOBJ=$(CXXTEST:.h=.o)
CXXBIN=$(CXXTEST:.h=.bin)
MAX_PARALLEL=6
OBJECTS=$(SOURCES:.cpp=.o)
BINS=$(SOURCES:.cpp=.b)
all: $(CXXBIN)
run: all
$(CXXCPP): $(subst .cpp,.h,[email protected])
cxxtestgen --error-printer -o [email protected] $(subst .cpp,.h,[email protected])
$(CXXOBJ): $(subst .o,.cpp,[email protected])
$(CC) $(CFLAGS) -o [email protected] $(subst .o,.cpp,[email protected])
$(CXXBIN): $(subst .bin,.o,[email protected])
$(CC) $(subst .bin,.o,[email protected]) $(OBJECTS) -o [email protected]
$(OBJECTS): $(subst .o,.cpp,[email protected])
$(CC) $(CFLAGS) $(subst .o,.cpp,[email protected]) -o [email protected]
$(BINS): $(subst .b,.o,[email protected])
$(CC) $(LDFLAGS) $(OBJECTS) -o [email protected]
clean:
rm -f LTest.cpp LTest LTest.o guitest guitest.o
然而,当我运行make LTest
其中LTest.h存在,请尝试运行
clang++ -c -Wall -std=c++11 -o LTest.o LTest.cpp
未做LTest.cpp第一。
显然,$(subst .o,.cpp,[email protected])
扩展到LTest.cpp,所以为什么不工作?
请记住,我是一个初学者在写makefile文件,所以如果有在做什么,我试图做我会很高兴地听到它一个更好的办法。 – byrondrossos
你可以发布你期望被调用的命令吗?你的makefile是不寻常的,它不知道它试图做什么。 –