I have built a make file for my project, and it works (everything compiles) but it gives these irritating error messages:
make: Circular zpr.c <- zpr.o dependency dropped. gcc -Wall -c -o zpr.o zpr.c make: Circular readjpeg.c <- readjpeg.o dependency dropped. gcc -Wall -c -o readjpeg.o readjpeg.c make: Circular readppm.c <- readppm.o dependency dropped. gcc -Wall -c -o readppm.o readppm.c make: Circular SceneNode.cpp <- SceneNode.o dependency dropped. g++ -c -o SceneNode.o SceneNode.cpp make: Circular BoundingBoxNode.cpp <- BoundingBoxNode.o dependency dropped. g++ -c -o BoundingBoxNode.o BoundingBoxNode.cpp make: Circular GeometryNode.cpp <- GeometryNode.o dependency dropped. g++ -c -o GeometryNode.o GeometryNode.cpp make: Circular SceneGraph.cpp <- SceneGraph.o dependency dropped. g++ -c -o SceneGraph.o SceneGraph.cpp make: Circular testgraph.cpp <- testgraph.o dependency dropped. g++ -c -o testgraph.o testgraph.cpp
My makefile is not complicated at all so hopefully someone can spot the error.
GXX=g++ CC=gcc CFLAGS=-Wall LIBS=-lGL -lglut -ljpeg OBJS=helpers.o loadobj.o zpr.o readjpeg.o readppm.o SceneNode.o BoundingBoxNode.o GeometryNode.o SceneGraph.o testgraph.o OBJS2=testgraph.o SceneGraph.o GeometryNode.o BoundingBox.o SceneNode.o readppm.o readjpeg.o zpr.o loadobj.o helpers.o SRCS=testgraph.cpp SceneGraph.cpp SceneNode.cpp .o.cpp: $(GXX) $(CFLAGS) -c $< .o.c: $(CC) $(CFLAGS) -c $< testgraph: $(OBJS) $(GXX) $(LIBS) $(OBJS) -o testgraph clean: rm *.o
Your implicit rules are the culprit. They have the extensions listed in the reverse order of how they are understood by make.
tells make that .c files are created from .o files. Since there is already a rule that says that .o files are created from .c files, you have a circular dependencies and therefore the errors.
The solution is (or should be, assuming a reasonably configured make) simple.
You don’t (usually) need to specify your own rules for compilation in really common cases, such as C++ sources. It would be simpler to just specify something like:
This is likely to also help you avoid two errors.
The rules you wrote say that .o files are created from .c files, which is backwards. But the correct rules already exist in nearly all versions of make.
You have listed the libraries ahead of the object files. This works by accident on some platforms that use ELF format objects. But it is still wrong. List libraries after objects because libraries are only loaded to satisfy undefined externals.