我正在尝试使用GCC(linux)和makefile来编译我的项目.
我得到以下错误,在这种情况下似乎无法破译:
"No rule to make target 'vertex.cpp', needed by 'vertex.o'. Stop."
Run Code Online (Sandbox Code Playgroud)
这是makefile:
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
Run Code Online (Sandbox Code Playgroud)
pax*_*blo 400
这通常是因为您没有vertex.cpp
可用的文件.检查:
除此之外,我没有其他建议.也许你可以给我们一个该目录的目录列表.
Wes*_*Wes 74
根据我的经验,此错误通常是由拼写错误引起的.
我今天收到了这个错误.
make [1]:***没有规则来制作目标
maintenaceDialog.cpp', needed by
maintenaceDialog.o'.停止.
在我的情况下,错误只是一个拼写错误.维护这个词错过了它的第三个N.
还要检查文件名的拼写.
Nic*_*son 13
在我的情况下,我使用逗号作为分隔符.为了使用你的例子,我做了这个:
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
Run Code Online (Sandbox Code Playgroud)
将其更改为相当于
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
Run Code Online (Sandbox Code Playgroud)
固定它.
我发现的问题甚至比其他人提到的还要愚蠢.
我们的makefile会传递要构建的东西列表.有人添加TheOtherLibrary
到其中一个列表中,如下所示.
LIBRARYDIRS = src/Library
LIBRARYDIRS = src/TheOtherLibrary
Run Code Online (Sandbox Code Playgroud)
他们应该这样做:
LIBRARYDIRS = src/Library
LIBRARYDIRS += src/TheOtherLibrary
Run Code Online (Sandbox Code Playgroud)
如果他们以第二种方式完成它,他们就不会消灭Library
构建.加号+=
非常重要.
在我的情况下,这是由于Makefile中的多行规则错误.我有类似的东西:
OBJS-$(CONFIG_OBJ1) += file1.o file2.o \
file3.o file4.o \
OBJS-$(CONFIG_OBJ2) += file5.o
OBJS-$(CONFIG_OBJ3) += file6.o
...
Run Code Online (Sandbox Code Playgroud)
CONFIG_OBJ1
's规则中文件列表末尾的反斜杠导致此错误.应该是这样的:
OBJS-$(CONFIG_OBJ1) += file1.o file2.o \
file3.o file4.o
OBJS-$(CONFIG_OBJ2) += file5.o
...
Run Code Online (Sandbox Code Playgroud)
常见错误之一可能是另一个文件名中的拼写错误。
你的例子很简单,但有时可能会混淆的是make
它本身的消息。让我们考虑一个例子。
我的文件夹内容是:
$ ls -1
another_file
index.md
makefile
Run Code Online (Sandbox Code Playgroud)
而我的makefile
样子
all: index.html
%.html: %.md wrong_path_to_another_file
@echo $@ $<
Run Code Online (Sandbox Code Playgroud)
虽然我确实有index.md
它应该在的地方并且它的名称没有错误,但来自的消息make
将是
make: *** No rule to make target `index.html', needed by `all'. Stop.
Run Code Online (Sandbox Code Playgroud)
说实话,这个消息令人困惑。它只是说,没有规则。事实上,这意味着规则是错误的,但由于通配符(模式)规则make
无法确定究竟是什么导致了问题。
让我们makefile
稍微改变一下,也就是说用显式规则替换模式:
index.html: index.md wrong_path_to_another_file
Run Code Online (Sandbox Code Playgroud)
现在我们得到的信息是:
make: *** No rule to make target `wrong_path_to_another_file', needed by `index.html'. Stop.
Run Code Online (Sandbox Code Playgroud)
奇迹!可以得出以下结论:
信息make
取决于规则,并不总是指向问题的根源
您可能存在与makefile
此消息指定的不同的其他问题
现在我们提出了在规则中检查其他依赖项的想法:
all: index.html
%.html: %.md another_file
@echo $@ $<
Run Code Online (Sandbox Code Playgroud)
只有这样才能为我们提供所需的结果:
$ make
index.html index.md
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
901805 次 |
最近记录: |