gcc makefile 错误:“没有规则可以生成目标...”

发布于 2024-07-18 07:36:39 字数 720 浏览 7 评论 0原文

我正在尝试使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(23

今天小雨转甜 2024-07-25 07:36:40

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

我今天收到这个错误。

make[1]: *** 没有规则可以生成目标maintenaceDialog.cpp',需要maintenaceDialog.o'。 停止。

就我而言,错误只是拼写错误。 “维护”一词丢失了,它的第三个 N。

还要检查文件名的拼写。

In my experience, this error is frequently caused by a spelling error.

I got this error today.

make[1]: *** No rule to make target maintenaceDialog.cpp', needed bymaintenaceDialog.o'. Stop.

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.

戏舞 2024-07-25 07:36:40

打印此消息的更常见原因是您忘记包含源文件所在的目录。 结果,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.

一场春暖 2024-07-25 07:36:40

就我而言,我愚蠢地使用逗号作为分隔符。 为了使用你的例子,我这​​样做了:

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

修复它。

In my case I had bone-headedly used commas as separators. To use your example I did this:

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

Changing it to the equivalent of

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

fixed it.

心不设防 2024-07-25 07:36:40

就我而言,这是因为我创建了像 MakeFile 这样的文件,而不是它应该是 Makefile

In my case it was due to I crated file like MakeFile instead it should be Makefile.

不知所踪 2024-07-25 07:36:40

真的是这样吗? 请记住,Makefile 语法可以识别空格,并且需要制表符来缩进操作下的命令。

Is that it exactly? Remember that Makefile syntax is whitespace aware and requires tabs to indent commands under actions.

野稚 2024-07-25 07:36:40

常见的错误之一可能是另一个文件名中的拼写错误

你的例子很简单,但有时可能会令人困惑的是
make 本身的消息。 让我们考虑一个例子。

我的文件夹内容是:

$ ls -1
another_file
index.md
makefile

虽然我的 makefile 看起来像

all: index.html

%.html: %.md wrong_path_to_another_file
    @echo $@ 
lt;

虽然我确实有 index.md 它应该在的位置,并且它的名称没有错误,但来自 < code>make 说

make: *** No rule to make target `index.html', needed by `all'.  Stop.

实话消息令人困惑。 它只是说,没有规则。 事实上,这意味着规则是错误的,但由于通配符(模式)规则,make无法确定到底是什么导致了问题。

让我们稍微改变一下 makefile ,也就是说用明确的规则替换模式:

index.html: index.md wrong_path_to_another_file

现在我们得到的消息将是:

make: *** No rule to make target `wrong_path_to_another_file', needed by `index.html'.  Stop.

奇迹! 可以得出以下结论:

  • make 的消息取决于规则,并不总是指向问题的根源

  • 您的 makefile 中可能存在与此消息指定的不同的其他问题

现在我们提出了检查规则中的其他依赖项的想法:

all: index.html

%.html: %.md another_file
    @echo $@ 
lt;

只有这样才能为我们提供所需的结果:

$ make
index.html index.md

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:

$ ls -1
another_file
index.md
makefile

Whereas my makefile looks like

all: index.html

%.html: %.md wrong_path_to_another_file
    @echo $@ 
lt;

Although I do have index.md where it should be and there is no mistake in the name of it, the message from make will be

make: *** No rule to make target `index.html', needed by `all'.  Stop.

To 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:

index.html: index.md wrong_path_to_another_file

And now the message we get will be:

make: *** No rule to make target `wrong_path_to_another_file', needed by `index.html'.  Stop.

Miracle! The following might be concluded:

  • Messages of make depends on rules and does not always point to the root of problems

  • There might be other problems in your makefile different from specified by this message

Now we've come up with the idea of checking other dependencies in a rule as well:

all: index.html

%.html: %.md another_file
    @echo $@ 
lt;

Only this will provide us with the desired result:

$ make
index.html index.md
红尘作伴 2024-07-25 07:36:40

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

我们的 makefile 获取要构建的内容的列表。 有人将 TheOtherLibrary 添加到其中一个列表中,如下所示。

LIBRARYDIRS = src/Library
LIBRARYDIRS = src/TheOtherLibrary

他们应该这样做:

LIBRARYDIRS = src/Library
LIBRARYDIRS += src/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.

LIBRARYDIRS = src/Library
LIBRARYDIRS = src/TheOtherLibrary

They should have done this:

LIBRARYDIRS = src/Library
LIBRARYDIRS += src/TheOtherLibrary

Had they done it the second way, they would not have wiped out the Library build. The plus in += is very important.

最美不过初阳 2024-07-25 07:36:40

就我而言,这是由于 Makefile 中的多行规则错误造成的。 我有类似的情况:

OBJS-$(CONFIG_OBJ1)            += file1.o file2.o \
                                  file3.o file4.o \
OBJS-$(CONFIG_OBJ2)            += file5.o 
OBJS-$(CONFIG_OBJ3)            += file6.o
...

CONFIG_OBJ1 规则中文件列表末尾的反斜杠导致了此错误。 它应该是这样的:

OBJS-$(CONFIG_OBJ1)            += file1.o file2.o \
                                  file3.o file4.o
OBJS-$(CONFIG_OBJ2)            += file5.o
...

In my case it was due to a multi-line rule error in the Makefile. I had something like:

OBJS-$(CONFIG_OBJ1)            += file1.o file2.o \
                                  file3.o file4.o \
OBJS-$(CONFIG_OBJ2)            += file5.o 
OBJS-$(CONFIG_OBJ3)            += file6.o
...

The backslash at the end of file list in CONFIG_OBJ1's rule caused this error. It should be like:

OBJS-$(CONFIG_OBJ1)            += file1.o file2.o \
                                  file3.o file4.o
OBJS-$(CONFIG_OBJ2)            += file5.o
...
奢欲 2024-07-25 07:36:40

如果您尝试构建 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

二手情话 2024-07-25 07:36:40

就我而言,错误消息引用了旧文件名,该文件名由于已重命名而不再存在。 原来过时的信息并不是来自Makefile,而是来自.deps目录下的文件。

将文件从一台计算机复制到另一台计算机后,我遇到了此错误。 在此过程中,我假设时间戳处于不一致的状态,这会在并行运行多个作业时混淆“make”(类似于 此错误报告)。

使用 make -j 1 的顺序构建不受影响,但我花了一段时间才意识到,因为我使用了别名 (make -j 8)。

为了清理状态,我删除了所有 .deps 文件并重新生成了 Makefile。 这些是我使用的命令:

find | grep '.deps' | xargs rm
find | grep '.deps' | xargs rmdir
autoreconf --install # (optional, but my project is using autotools) 
./configure

之后,构建再次开始工作。

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:

find | grep '.deps' | xargs rm
find | grep '.deps' | xargs rmdir
autoreconf --install # (optional, but my project is using autotools) 
./configure

After that, building worked again.

初见终念 2024-07-25 07:36:40

就我而言,出现此错误的原因是文件夹名称中有空格,重命名文件夹解决了问题


示例:

~/foo bar/mymoduledir

将文件夹 foo bar 重命名为 foo_bar

~/foo_bar/mymoduledir

解决问题

In my case, the reason for this error was that a folder name had a space, renaming the folder solved the problem


Example:

~/foo bar/mymoduledir

renaming the folder foo bar to foo_bar:

~/foo_bar/mymoduledir

fixes the problem

狼性发作 2024-07-25 07:36:40

就我而言,路径未在 VPATH 中设置,添加后错误消失。

In my case the path is not set in VPATH, after added the error gone.

小梨窩很甜 2024-07-25 07:36:40

我的情况是缺少 $

而不是:

(LINK_TARGET): $(OBJS)

应该是:

$(LINK_TARGET): $(OBJS)

编辑:

我遇到了同样的问题,但现在由于另一个原因,这是由于内部的 echo 命令我的 .bashrc 文件。

My case was a missing $:

Instead of:

(LINK_TARGET): $(OBJS)

Should be:

$(LINK_TARGET): $(OBJS)

Edit:

I had this same problem, but now due to another reason, it was due to an echo command inside my .bashrc file.

放手` 2024-07-25 07:36:40

另一个奇怪问题及其解决方案的例子:

这:

target_link_libraries(
    ${PROJECT_NAME}
    ${Poco_LIBRARIES}
    ${Poco_Foundation_LIBRARY}
    ${Poco_Net_LIBRARY}
    ${Poco_Util_LIBRARY}
    )

给出: make[3]: *** 没有规则可以生成 '../hello_poco/bin 需要的目标 '/usr/lib/libPocoFoundationd.so' /mac/HelloPoco'。 停止。

但是如果我删除 Poco_LIBRARIES 它就可以工作:

target_link_libraries(
    ${PROJECT_NAME}
    ${Poco_Foundation_LIBRARY}
    ${Poco_Net_LIBRARY}
    ${Poco_Util_LIBRARY}
    )

我在 Mac 上使用 clang8,在 Linux 上使用 clang 3.9
该问题仅出现在 Linux 上,但在 Mac 上却可以!

我忘了提及:Poco_LIBRARIES 是错误的 - 它不是由 cmake/find_package 设置的!

Another example of a weird problem and its solution:

This:

target_link_libraries(
    ${PROJECT_NAME}
    ${Poco_LIBRARIES}
    ${Poco_Foundation_LIBRARY}
    ${Poco_Net_LIBRARY}
    ${Poco_Util_LIBRARY}
    )

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:

target_link_libraries(
    ${PROJECT_NAME}
    ${Poco_Foundation_LIBRARY}
    ${Poco_Net_LIBRARY}
    ${Poco_Util_LIBRARY}
    )

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!

别靠近我心 2024-07-25 07:36:40

导致此错误的原因有多种。

我遇到此错误的原因之一是在为 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

风为裳 2024-07-25 07:36:40

这条消息可以清楚地表达很多意思。

就我而言,它是使用多线程进行编译的。 一个线程需要另一个线程尚未完成的依赖项,从而导致错误。

并非所有构建都是线程安全的,因此如果您的构建通过了其他测试(例如上面列出的测试),请考虑使用一个线程进行慢速构建。

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.

苏璃陌 2024-07-25 07:36:40

当我忘记将新文件添加到我的 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.

醉城メ夜风 2024-07-25 07:36:40

就我而言,源和/或旧目标文件被半崩溃的 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.

最丧也最甜 2024-07-25 07:36:40

就我而言,删除一些头文件和 .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

我只土不豪 2024-07-25 07:36:40

此错误清楚地表明您的 cmake 中缺少要安装的目标。
在编写 Cmake 时遇到了这个问题,如下所示:

cmake_minimum_required(VERSION 3.10.2)
project(project_name)

include_directories(
 ${CMAKE_HOME_DIRECTORY}/xxxx     
)
//called some subfolders with their cmake and worked fine
add_subdirectory(ABC)  //this had executable target and intall location etc

//if commented above there was no target to install (there are no source files/no executable/library to create??

参考资料取自: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:

cmake_minimum_required(VERSION 3.10.2)
project(project_name)

include_directories(
 ${CMAKE_HOME_DIRECTORY}/xxxx     
)
//called some subfolders with their cmake and worked fine
add_subdirectory(ABC)  //this had executable target and intall location etc

//if commented above there was no target to install (there are no source files/no executable/library to create??

Reference taken from: https://cmake.org/cmake/help/book/mastering-cmake/

吐个泡泡 2024-07-25 07:36:40

就我而言,这是因为我调用了 Makefile:MAKEFILE(全部大写)

In my case, it was due to me calling the Makefile: MAKEFILE (all caps)

口干舌燥 2024-07-25 07:36:40

我写了错误的文件名,如 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.

后知后觉 2024-07-25 07:36:39

这通常是因为您没有可供创建的名为 vertex.cpp 的文件。 检查:

  • 该文件存在。
  • 当你制作时,你就在正确的目录中。

除此之外,我没有太多其他建议。 也许您可以给我们该目录的目录列表。

That's usually because you don't have a file called vertex.cpp available to make. Check that:

  • that file exists.
  • you're in the right directory when you make.

Other than that, I've not much else to suggest. Perhaps you could give us a directory listing of that directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文