make:***没有规则来实现目标' oprogram.exe; exe'所需的目标。停止

发布于 2025-01-29 16:44:32 字数 278 浏览 1 评论 0原文

我在SRC文件夹中有源文件,当我运行make(Windows)时,我会收到以下错误 制作:***没有规则来制作目标“%.o”,“ program.exe”所需的规则。停止。

VPATH := src

Program.exe : %.o
    g++.exe -o bin/program.exe  $<


%.o : %.cpp
    echo $<
    g++ -c -ILibraries/include -LLibraries/lib $< -lgdi32

i have my source files inside the src folder and when i run make (windows) i get the following error
make: *** No rule to make target '%.o', needed by 'Program.exe'. Stop.

VPATH := src

Program.exe : %.o
    g++.exe -o bin/program.exe  
lt;


%.o : %.cpp
    echo 
lt;
    g++ -c -ILibraries/include -LLibraries/lib 
lt; -lgdi32

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

晨曦慕雪 2025-02-05 16:44:32

Make中的不是与文件匹配的通配符。同样,因为当开始启动时,不会有任何.o文件要匹配。

Make中的是模式匹配,它仅在模式规则中起作用:模式规则必须在 target 中具有(如第二规则您有,%。o:%.c)。如果您的目标中没有,那么请思考先决条件列表中的是一个正常字符,例如ab或其他。 MAKE不知道如何创建名为nathly的文件,字面上是%。o,因为没有匹配的%。cpp文件。

同样,创建不等于$@的文件总是错误的。在这里,您的目标是program.exe,但是您的食谱会创建一个文件bin/program.exe:这些不是同一回事,所以这是错误的。

另外,$&lt;只是第一个先决条件:当您要将大量文件链接在一起时,您要使用$^,这是所有先决条件。

您需要列出要创建的所有对象文件:

bin/program.exe: src/foo.o src/bar.o src/baz.o
        g++.exe -o $@ $^

如果要自动生成所有对象文件,则假设您要编译所有源文件,则可以做类似的事情:

OBJS := $(patsubst %.cpp,%.o,$(wildcard src/*.cpp))

bin/program.exe: $(OBJS)
        g++.exe -o $@ $^

您不需要在这种情况;它无济于事。

The % in make is not a wildcard that matches files. Just as well, because when make starts there won't be any .o files to match.

The % in make is a pattern match and it only works in pattern rules: pattern rules must have a % in the target (like the second rule you have, %.o : %.c). If you don't have a % in the target, then make just thinks that the % in the prerequisite list is a normal character like an a or b or whatever. Make doesn't know how to create a file named, literally, %.o because there is no matching %.cpp file.

Also it's always wrong in make to create a file that is not equal to $@. Here your target is Program.exe but your recipe creates a file bin/program.exe: those are not the same thing so it's wrong.

Also $< is only the FIRST prerequisite: when you want to link lots of files together you want to use $^ which is all the prerequisites.

You need to list all the object files you want to create:

bin/program.exe: src/foo.o src/bar.o src/baz.o
        g++.exe -o $@ $^

If you want to automatically generate all the object files then, assuming you want to compile all the source files, you can do something like:

OBJS := $(patsubst %.cpp,%.o,$(wildcard src/*.cpp))

bin/program.exe: $(OBJS)
        g++.exe -o $@ $^

You don't need to set VPATH in this situation; it doesn't help.

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