Reputation: 3
I am having problems with my makefile
It looks like this
name = project-name
testfiles = $(wildcard tst/*.cxx)
sourcefiles = $(wildcard src/*.cpp)
headerfiles = $(wildcard inc/*.hpp)
tests = $(testfiles:%=%.o)
sources = $(sourcefiles:%=%.o)
headers = $(headerfiles:%=%.gch)
location = /usr/local/include
flags = -Iinc -std=c++17 -pedantic -Wall
all: $(name)
%/:
mkdir -p $@
clean:
rm -f $(tests) $(sources) $(headers) $(name) test
install: $(name)
install $^ $(location)/$<
run-%: %
./$<
test: $(tests)
g++ -o $@ $^
$(name): $(sources)
g++ -o $@ $^
pch: $(headers)
%.gch: %
g++ -o $@ $< $(flags)
tst/catch.cxx.o: tst/catch.cxx inc/catchmain.hpp.gch
g++ -o $@ -c $< $(flags)
tst/receive.cxx.o: tst/receive.cxx inc/catchtest.hpp.gch inc/server.hpp.gch
g++ -o $@ -c $< $(flags)
src/server.cpp.o: src/server.cpp inc/server.hpp.gch inc/iostream.hpp.gch
g++ -o $@ -c $< $(flags)
My folder structure is like this (image attached)
.
├── inc
│ ├── catchmain.hpp
│ ├── catchtest.hpp
│ ├── iostream.hpp
│ └── server.hpp
├── makefile
├── src
│ └── server.cpp
└── tst
├── catch.cxx
└── receive.cxx
And when I run
make test
It shows that it dropped a circular dependency. I don't see what might cause that.
# The output of `make test`
make: Circular tst/catch.cxx <- tst/catch.cxx.o dependency dropped.
g++ -o inc/catchmain.hpp.gch inc/catchmain.hpp -Iinc -std=c++17 -pedantic -Wall
g++ -o tst/catch.cxx.o -c tst/catch.cxx -Iinc -std=c++17 -pedantic -Wall
make: Circular tst/receive.cxx <- tst/receive.cxx.o dependency dropped.
g++ -o inc/catchtest.hpp.gch inc/catchtest.hpp -Iinc -std=c++17 -pedantic -Wall
g++ -o inc/server.hpp.gch inc/server.hpp -Iinc -std=c++17 -pedantic -Wall
g++ -o tst/receive.cxx.o -c tst/receive.cxx -Iinc -std=c++17 -pedantic -Wall
g++ -o test tst/catch.cxx.o tst/receive.cxx.o
Upvotes: 0
Views: 78
Reputation: 26727
You had Circular dependency
because
%: %.o
is a gnu make implicit rule
Upvotes: 0
Reputation: 3
I just changed the extension from cxx
to cpp
and everything works without any errors. Weird
Upvotes: 0