Jeggu
Jeggu

Reputation: 579

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.

Upvotes: 1

Views: 5703

Answers (1)

Beta
Beta

Reputation: 99084

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

Upvotes: 3

Related Questions