make:***没有规则来实现目标' oprogram.exe; exe'所需的目标。停止
我在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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Make中的
%
不是与文件匹配的通配符。同样,因为当开始启动时,不会有任何.o
文件要匹配。Make中的
%
是模式匹配,它仅在模式规则中起作用:模式规则必须在 target 中具有%
(如第二规则您有,%。o:%.c
)。如果您的目标中没有%
,那么请思考先决条件列表中的%
是一个正常字符,例如a
或b
或其他。 MAKE不知道如何创建名为nathly的文件,字面上是%。o
,因为没有匹配的%。cpp
文件。同样,创建不等于
$@
的文件总是错误的。在这里,您的目标是program.exe
,但是您的食谱会创建一个文件bin/program.exe
:这些不是同一回事,所以这是错误的。另外,
$&lt;
只是第一个先决条件:当您要将大量文件链接在一起时,您要使用$^
,这是所有先决条件。您需要列出要创建的所有对象文件:
如果要自动生成所有对象文件,则假设您要编译所有源文件,则可以做类似的事情:
您不需要在这种情况;它无济于事。
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 ana
orb
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 isProgram.exe
but your recipe creates a filebin/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:
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:
You don't need to set VPATH in this situation; it doesn't help.