简体   繁体   中英

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.

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) 

I have only one .cpp and .h file. Please someone correct it.

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))

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 $@

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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