简体   繁体   English

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: 我正在尝试为我的项目创建一个makefile,但在运行它时我得到一个错误,如:

make: Circular database.cpp <- database.cpp dependency dropped

make: database.cpp' is up to date.

Here is my Makefile: 这是我的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) 

I have only one .cpp and .h file. 我只有一个.cpp.h文件。 Please someone correct it. 请有人纠正。

You have an extra space in your patsubst which is preventing a correct match, so that OBJFILES is "database.cpp". 您的patsubst有一个额外的空间阻止正确匹配,因此OBJFILES是“database.cpp”。 You can correct it like so: 你可以像这样纠正它:

OBJFILES = $(patsubst %.cpp,%.o ,$(wildcard *.cpp))

But that still leaves you with a makefile that will fail badly when you add a second source file to the codebase. 但是,当您向代码库添加第二个源文件时,仍然会留下一个makefile,它会严重失败。 I suggest you do it this way: 我建议你这样做:

$(OBJFILES): %.o : %.cpp $(HEADERFILES)
    g++ -c -o $@ $<
    ar rvs libdatabase.a $@

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM