tags:

views:

2668

answers:

1

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
+7  A: 

Your implicit rules are the culprit. They have the extensions listed in the reverse order of how they are understood by make.

.o.c:

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:

CFLAGS=-Wall
LOADLIBES=-lGL -lglut -ljpeg

OBJS=helpers.o loadobj.o zpr.o readjpeg.o readppm.o SceneNode.o \
   BoundingBoxNode.o GeometryNode.o SceneGraph.o  testgraph.o 

all: testgraph

testgraph: $(OBJS)

This is likely to also help you avoid two errors.

  1. 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.

  2. 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.

RBerteig
Thanks a lot, that removed the circular dependency messages.I figured out that there was also a CXXFLAGS variable, so that works as well.gcc is used for C, and g++ for C++, as I want it. But why is it using "cc" for linking? Do I have to worry?
kigurai
Since it is probable that cc is a link to gcc, and that would be ok. I am pretty sure that both gcc and g++ will link a mixed application just fine. However, conventional wisdom does have it that a C++ compiler driver should be used instead of a C driver for linking mixed code.
RBerteig