Makefile循环依赖项已删除 [英] Makefile circular dependency dropped
问题描述
我正在尝试为我的项目创建一个生成文件,但是在运行该文件时出现错误 像:
I am trying to create a makefile for my project, but while running it I am getting an error like:
make: Circular database.cpp <- database.cpp dependency dropped
make: database.cpp' is up to date.
这是我的Makefile:
Here is my Makefile:
HEADERFILES = $(wildcard *.h)
CPPFILES = $(wildcard *.cpp)
OBJFILES = $(patsubst %.cpp ,%.o ,$(wildcard *.cpp))
$(OBJFILES): $(CPPFILES) $(HEADERFILES)
g++ -c -o $(OBJFILES) $(CPPFILES)
ar rvs libdatabase.a $(OBJFILES)
我只有一个.cpp
和.h
文件.请有人纠正它.
I have only one .cpp
and .h
file. Please someone correct it.
推荐答案
您的patsubst
中有多余的空间,阻止了正确的匹配,因此OBJFILES
是"database.cpp".您可以像这样纠正它:
You have an extra space in your patsubst
which is preventing a correct match, so that OBJFILES
is "database.cpp". You can correct it like so:
OBJFILES = $(patsubst %.cpp,%.o ,$(wildcard *.cpp))
但是,这仍然会使您留下一个makefile,当您向代码库中添加第二个源文件时,makefile将会严重失败.我建议您这样做:
But that still leaves you with a makefile that will fail badly when you add a second source file to the codebase. I suggest you do it this way:
$(OBJFILES): %.o : %.cpp $(HEADERFILES)
g++ -c -o $@ $<
ar rvs libdatabase.a $@
这篇关于Makefile循环依赖项已删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!