我试图使用GCC (linux)与makefile编译我的项目。

我得到了以下错误,似乎无法在这种情况下破译:

"No rule to make target 'vertex.cpp', needed by 'vertex.o'.  Stop."

这是生成文件:

a.out: vertex.o edge.o elist.o main.o vlist.o enode.o vnode.o
    g++ vertex.o edge.o elist.o main.o vlist.o enode.o vnode.o

main.o: main.cpp main.h
    g++ -c main.cpp

vertex.o: vertex.cpp vertex.h
    g++ -c vertex.cpp

edge.o: edge.cpp edge.h
    g++ -c num.cpp

vlist.o: vlist.cpp vlist.h
    g++ -c vlist.cpp

elist.o: elist.cpp elist.h
    g++ -c elist.cpp

vnode.o: vnode.cpp vnode.h
    g++ -c vnode.cpp

enode.o: enode.cpp enode.h
    g++ -c node.cpp

当前回答

在我的例子中,源文件和/或旧目标文件被半崩溃的IDE或停止正常工作的备份云服务锁定(只读)。重新启动与文件夹结构相关联的所有程序和服务就解决了这个问题。

其他回答

我发现的问题比其他人提到的更愚蠢。

我们的makefile会得到要构建的东西的列表。有人将TheOtherLibrary添加到其中一个列表,如下所示。

LIBRARYDIRS = src/Library
LIBRARYDIRS = src/TheOtherLibrary

他们应该这样做:

LIBRARYDIRS = src/Library
LIBRARYDIRS += src/TheOtherLibrary

如果他们采用第二种方法,他们就不会摧毁图书馆了。+=中的加号非常重要。

这通常是因为您没有一个名为vertex.cpp的文件可用。检查:

该文件存在。 你在正确的目录下。

除此之外,我没有什么建议了。也许你能给我们一份那个目录的目录清单。

根据我的经验,这个错误通常是由拼写错误引起的。

我今天收到这个错误。

make[1]: ***没有创建目标maintenaceDialog.cpp'的规则,maintenacedialog .o'需要。停止。

在我的例子中,这个错误只是一个拼写错误。MAINTENANCE这个词缺了第三个N。

还要检查文件名的拼写。

在我的例子中,我愚蠢地使用逗号作为分隔符。用你的例子来说,我是这样做的:

a.out: vertex.o, edge.o, elist.o, main.o, vlist.o, enode.o, vnode.o
    g++ vertex.o edge.o elist.o main.o vlist.o enode.o vnode.o

把它换成

a.out: vertex.o edge.o elist.o main.o vlist.o enode.o vnode.o
    g++ vertex.o edge.o elist.o main.o vlist.o enode.o vnode.o

固定它。

当我忘记向我的git存储库添加新文件时,在Travis内部发生了这个错误。愚蠢的错误,但我可以看出这是相当普遍的。