为什么要抱怨循环依赖? [英] Why is make complaining about circular dependencies?

查看:189
本文介绍了为什么要抱怨循环依赖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的项目构建了一个make文件,并且该文件可以运行(一切都可以编译),但是却给出了这些令人讨厌的错误消息:

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

我的makefile一点也不复杂,所以希望有人能发现错误.

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

推荐答案

您的隐式规则是元凶.它们的扩展名与make理解的顺序相反.

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

.o.c:

告诉我们说.c文件是从.o文件创建的.由于已经有一个规则说.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.

解决方案很简单(或者应该是合理配置的make).

The solution is (or should be, assuming a reasonably configured make) simple.

在真正常见的情况下,例如C ++源代码,您通常不需要指定自己的编译规则.只指定类似以下内容会更简单:

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. 您编写的规则说.o文件是从.c文件创建的,这是向后的.但是正确的规则已经存在于几乎所有版本的make中.

  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.

您已在目标文件之前列出了库.在某些使用ELF格式对象的平台上,这偶然发生了.但这仍然是错误的.在对象之后列出库,因为仅加载库以满足未定义的外部条件.

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.

这篇关于为什么要抱怨循环依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆