Makefile 错误:没有规则可生成目标
SOURCES = server.c
TARGET = Server
CC = gcc
all: $(SOURCES) $(TARGET)
$(CC) $(SOURCES) -o $(TARGET)
clean:
rm -rf $(TARGET)
上面是我的网络服务器的 Makefile。尽管 server.c 文件位于目录中,但这会出现以下错误
make: *** No rule to make target `Server', needed by `all'. Stop.
我犯了什么错误以及如何解决它。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你的 makefile 在你的机器和帖子之间的某个地方出现了乱码,但是我认为有一个简单的修复方法可以工作:
这将(可能)解决问题并使错误消失 - 如果这就是你想要的那么你可以停止阅读。但是这个makefile仍然有问题,所以我们可以做一些更多的改进。
首先,进行一些调整,使其符合我认为您的 makefile 真正所说的内容:
前三行和
clean
规则都可以,我们将忽略它们。现在我们给TARGET
自己的规则并理清先决条件:现在我们制作
all
PHONY (因为它并没有真正制作一个名为“all”的文件),并引入自动变量使TARGET
规则更强大且更少冗余:如果您的代码库变得更复杂,则需要学习更多内容,但现在就这样了。
I think your makefile got garbled somewhere between your machine and the post, but there is a simple fix that I think will work:
That will (probably) solve the problem and make the error go away-- if that's all you want then you can stop reading. But there are still things wrong with this makefile, so we can make some more improvements.
First, a little adjustment to make it match what I think your makefile really says:
The first three lines and the
clean
rule are all right, we'll ignore those. Now we giveTARGET
its own rule and straighten out the prerequisites:Now we make
all
PHONY (since it doesn't really make a file called "all"), and introduce automatic variables to make theTARGET
rule more robust and less redundant:There's more to learn if your codebase gets more complicated, but that'll do for now.
只需执行“make clean”来清理所有链接,然后再次运行 make 即可。一切都应该很好。
just do "make clean" to clean all links, then run make again. Everything should be good.
我的问题是我的名称和命令在同一行。确保:确保您使用的是制表符而不是空格。 (无双关语)
之前(破碎)
之后
My issues was I had the name and the command on the same line. Make: sure you are using tabs and not spaces. (no pun intended)
BEFORE (Broken)
AFTER