gcc makefile 错误:“没有规则可以生成目标...”
我正在尝试使用 GCC (linux) 和 makefile 来编译我的项目。
我收到以下错误,在这种情况下似乎无法破译:
"No rule to make target 'vertex.cpp', needed by 'vertex.o'. Stop."
这是 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
I'm trying to use GCC (linux) with a makefile to compile my project.
I get the following error which is can't seem to decipher in this context:
"No rule to make target 'vertex.cpp', needed by 'vertex.o'. Stop."
This is the 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(23)
根据我的经验,此错误通常是由拼写错误引起的。
我今天收到这个错误。
就我而言,错误只是拼写错误。 “维护”一词丢失了,它的第三个 N。
还要检查文件名的拼写。
In my experience, this error is frequently caused by a spelling error.
I got this error today.
In my case the error was simply a spelling error. The word MAINTENANCE was missing it's third N.
Also check the spelling on your filenames.
打印此消息的更常见原因是您忘记包含源文件所在的目录。 结果,gcc“认为”这个文件不存在。
您可以使用 gcc 的 -I 参数添加目录。
The more common reason for this message to be printed is because you forgot to include the directory in which the source file resides. As a result, gcc "thinks" this file does not exist.
You can add the directory using the -I argument to gcc.
就我而言,我愚蠢地使用逗号作为分隔符。 为了使用你的例子,我这样做了:
将其更改为相当于
修复它。
In my case I had bone-headedly used commas as separators. To use your example I did this:
Changing it to the equivalent of
fixed it.
就我而言,这是因为我创建了像
MakeFile
这样的文件,而不是它应该是Makefile
。In my case it was due to I crated file like
MakeFile
instead it should beMakefile
.真的是这样吗? 请记住,Makefile 语法可以识别空格,并且需要制表符来缩进操作下的命令。
Is that it exactly? Remember that Makefile syntax is whitespace aware and requires tabs to indent commands under actions.
常见的错误之一可能是另一个文件名中的拼写错误。
你的例子很简单,但有时可能会令人困惑的是
make
本身的消息。 让我们考虑一个例子。我的文件夹内容是:
虽然我的
makefile
看起来像虽然我确实有
index.md
它应该在的位置,并且它的名称没有错误,但来自 < code>make 说实话消息令人困惑。 它只是说,没有规则。 事实上,这意味着规则是错误的,但由于通配符(模式)规则,
make
无法确定到底是什么导致了问题。让我们稍微改变一下
makefile
,也就是说用明确的规则替换模式:现在我们得到的消息将是:
奇迹! 可以得出以下结论:
make
的消息取决于规则,并不总是指向问题的根源您的
makefile
中可能存在与此消息指定的不同的其他问题现在我们提出了检查规则中的其他依赖项的想法:
只有这样才能为我们提供所需的结果:
One of frequent mistakes might be typo in another file name.
You example is quite straightforward but what may sometimes confuse are
messages of
make
itself. Lets consider an example.My folder contents is:
Whereas my
makefile
looks likeAlthough I do have
index.md
where it should be and there is no mistake in the name of it, the message frommake
will beTo be honest the message is confusing. It just says, that there is no rule. In fact, it means that the rule is wrong, but due to wildcard (pattern) rules
make
cannot determine what exactly caused the issue.Lets alter
makefile
a little, which is to say replace patterns with explicit rules:And now the message we get will be:
Miracle! The following might be concluded:
Messages of
make
depends on rules and does not always point to the root of problemsThere might be other problems in your
makefile
different from specified by this messageNow we've come up with the idea of checking other dependencies in a rule as well:
Only this will provide us with the desired result:
我发现的问题比其他人提到的更愚蠢。
我们的 makefile 获取要构建的内容的列表。 有人将
TheOtherLibrary
添加到其中一个列表中,如下所示。他们应该这样做:
如果他们以第二种方式完成,他们就不会消除
Library
构建。+=
中的加号非常重要。The problem I found was even sillier than what other folks have mentioned.
Our makefiles get passed lists of things to build. Someone added
TheOtherLibrary
to one of the lists, as shown below.They should have done this:
Had they done it the second way, they would not have wiped out the
Library
build. The plus in+=
is very important.就我而言,这是由于 Makefile 中的多行规则错误造成的。 我有类似的情况:
CONFIG_OBJ1
规则中文件列表末尾的反斜杠导致了此错误。 它应该是这样的:In my case it was due to a multi-line rule error in the Makefile. I had something like:
The backslash at the end of file list in
CONFIG_OBJ1
's rule caused this error. It should be like:如果您尝试构建 John the Ripper“bleeding-jumbo”并收到类似“make: *** Norule to make target 'linux-x86-64'”的错误。 尝试运行此命令:
./configure && 制作
If you are trying to build John the Ripper "bleeding-jumbo" and get an error like "make: *** No rule to make target 'linux-x86-64'". Try running this command instead:
./configure && make
就我而言,错误消息引用了旧文件名,该文件名由于已重命名而不再存在。 原来过时的信息并不是来自Makefile,而是来自
.deps
目录下的文件。将文件从一台计算机复制到另一台计算机后,我遇到了此错误。 在此过程中,我假设时间戳处于不一致的状态,这会在并行运行多个作业时混淆“make”(类似于 此错误报告)。
使用
make -j 1
的顺序构建不受影响,但我花了一段时间才意识到,因为我使用了别名 (make -j 8
)。为了清理状态,我删除了所有
.deps
文件并重新生成了 Makefile。 这些是我使用的命令:之后,构建再次开始工作。
In my case, the error message referred to an old filename, which did no longer exist because it was renamed. It turned out that the outdated information did not come from the Makefile, but from files in
.deps
directories.I ran into this error after copying files from one machine to another. In that process, I assume the timestamps got in an inconsistent state, which confused "make" when running multiple jobs in parallel (similar to this bug report).
Sequential builds with
make -j 1
were not affected, but it took me a while to realize because I was using an alias (make -j 8
).To clean up the state, I removed all
.deps
files and regenerated the Makefile. These are the commands that I used:After that, building worked again.
就我而言,出现此错误的原因是文件夹名称中有空格,重命名文件夹解决了问题
示例:
将文件夹
foo bar
重命名为foo_bar
:解决问题
In my case, the reason for this error was that a folder name had a space, renaming the folder solved the problem
Example:
renaming the folder
foo bar
tofoo_bar
:fixes the problem
就我而言,路径未在 VPATH 中设置,添加后错误消失。
In my case the path is not set in VPATH, after added the error gone.
我的情况是缺少
$
:而不是:
应该是:
编辑:
我遇到了同样的问题,但现在由于另一个原因,这是由于内部的
echo
命令我的 .bashrc 文件。My case was a missing
$
:Instead of:
Should be:
Edit:
I had this same problem, but now due to another reason, it was due to an
echo
command inside my.bashrc
file.另一个奇怪问题及其解决方案的例子:
这:
给出:
make[3]: *** 没有规则可以生成 '../hello_poco/bin 需要的目标 '/usr/lib/libPocoFoundationd.so' /mac/HelloPoco'。 停止。
但是如果我删除
Poco_LIBRARIES
它就可以工作:我在 Mac 上使用 clang8,在 Linux 上使用 clang 3.9
该问题仅出现在 Linux 上,但在 Mac 上却可以!
我忘了提及:
Poco_LIBRARIES
是错误的 - 它不是由 cmake/find_package 设置的!Another example of a weird problem and its solution:
This:
gives:
make[3]: *** No rule to make target '/usr/lib/libPocoFoundationd.so', needed by '../hello_poco/bin/mac/HelloPoco'. Stop.
But if I remove
Poco_LIBRARIES
it works:I'm using clang8 on Mac and clang 3.9 on Linux
The problem only occurs on Linux but works on Mac!
I forgot to mention:
Poco_LIBRARIES
was wrong - it was not set by cmake/find_package!导致此错误的原因有多种。
我遇到此错误的原因之一是在为 Linux 和 Windows 构建时。
我有一个带有大写字母的文件名 BaseClass.h SubClass.h
Unix 保持区分大小写的文件命名约定,而 Windows 不区分大小写。
C++ 为什么人们在名称中不使用大写字母头文件?
如果您使用 gmake,请尝试使用 gmake clean 编译干净的版本。
某些文本编辑器的默认设置会忽略区分大小写的文件名。 这也可能导致同样的错误。
如何在 Qt Creator 中添加一个名称以大写字母开头的 c++ 文件? 它会自动将其变成小写字母
There are multiple reasons for this error.
One of the reason where i encountered this error is while building for linux and windows.
I have a filename with caps BaseClass.h SubClass.h
Unix maintains has case-sensitive filenaming convention and windows is case-insensitive.
C++ why people don't use uppercase in name of header files?
Try compiling clean build using gmake clean if you are using gmake
Some text editors has default settings to ignore case-sensitive filenames. This could also lead to the same error.
how to add a c++ file in Qt Creator whose name starts with capital letters ? It automatically makes it small letter
这条消息可以清楚地表达很多意思。
就我而言,它是使用多线程进行编译的。 一个线程需要另一个线程尚未完成的依赖项,从而导致错误。
并非所有构建都是线程安全的,因此如果您的构建通过了其他测试(例如上面列出的测试),请考虑使用一个线程进行慢速构建。
This message can mean many things clearly.
In my case it was compiling using multiple threads. One thread needed a dependency that another thread hadn't finished making, causing an error.
Not all builds are threadsafe, so consider a slow build with one thread if your build passes other tests such as the ones listed above.
当我忘记将新文件添加到我的 git 存储库时,Travis 内部发生了这个错误。 愚蠢的错误,但我可以看到它很常见。
This error occurred for me inside Travis when I forgot to add new files to my git repository. Silly mistake, but I can see it being quite common.
就我而言,源和/或旧目标文件被半崩溃的 IDE 或停止正常工作的备份云服务锁定(只读)。 重新启动与文件夹结构关联的所有程序和服务解决了该问题。
In my case, the source and/or old object file(s) were locked (read-only) by a semi-crashed IDE or from a backup cloud service that stopped working properly. Restarting all programs and services that were associated with the folder structure solved the problem.
就我而言,删除一些头文件和 .c 文件后问题就出现了,并且项目未编译。
运行clean,然后build编译项目
In my case the issue popped out after removing some of the header files and .c files and the project didn't compile.
Running clean and then build compiled the project
此错误清楚地表明您的 cmake 中缺少要安装的目标。
在编写 Cmake 时遇到了这个问题,如下所示:
参考资料取自:https://cmake。 org/cmake/help/book/mastering-cmake/
This error clearly indicates that in your cmake is missing the target to install.
Encountered this when wrote a Cmake as below:
Reference taken from: https://cmake.org/cmake/help/book/mastering-cmake/
就我而言,这是因为我调用了 Makefile:MAKEFILE(全部大写)
In my case, it was due to me calling the Makefile: MAKEFILE (all caps)
我写了错误的文件名,如 MakeFile 我也得到了 make: *** 没有规则来制作目标“gen”。 停止。 我发现我错误地将文件名重命名为 Makefile,然后就没事了。
i have write mistake the file name like MakeFile i also get the make: *** No rule to make target `gen'. Stop. i find i mistake the file name i rename to Makefile and then i get okay.
这通常是因为您没有可供创建的名为
vertex.cpp
的文件。 检查:除此之外,我没有太多其他建议。 也许您可以给我们该目录的目录列表。
That's usually because you don't have a file called
vertex.cpp
available to make. Check that:Other than that, I've not much else to suggest. Perhaps you could give us a directory listing of that directory.