makefile 的问题
hiii,我刚刚开始研究 makefile,并为一个简单的 hello.c 文件编写了以下文件。它显示一些错误:
makefile1:5: *** 缺少分隔符。停止。
这里出了什么问题...?
CC=gcc
CFLAGS=-c -Wall
hello: hello.c
$(CC) $(CFLAGS) hello.c -o hello
clean:
rm -rf *.o
并且,使用 makefile 是否总是更好的选择,或者有任何特定情况不使用它们......?
如果我有什么错误的地方请纠正我...
hiii , i just started studying makefiles and wrote the following one for a simple hello.c file. it shows some error saying :
makefile1:5: *** missing separator. Stop.
What is the wrong here ... ?
CC=gcc
CFLAGS=-c -Wall
hello: hello.c
$(CC) $(CFLAGS) hello.c -o hello
clean:
rm -rf *.o
And , Is it always a better option to use a makefile or there are any specific cases to not use them ...?
Please correct me if i am wrong anywhere ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在编写生成目标的规则之前,请确保没有丢失任何选项卡:
最好编写
.PHONY
。您可以在此处找到原因。Make sure you are not missing any tabs before you write the rule to generate a target:
Its good to write the
.PHONY
. You can find the reason here.首先,你的目标不应该缩进。其次,确保使用制表符而不是空格来缩进。
至于你的另一个问题,makefile 无处不在。无论您是否喜欢它们,学习如何维护它们都是一个好主意。就我个人而言,我喜欢它们的魔力。它们可以极大地节省时间。如果您发现自己必须调试复杂的程序,它们也可能会浪费大量时间。
First, your targets should not be indented. Second, make sure you're using tab characters not spaces to indent.
As to your other question, makefiles are used everywhere. Whether you like them or not, learning how to maintain them is a good idea. Personally, I like how magic they are. They can be great time savers. They can also be horrendous time sinks if you find yourself having to debug complex ones.
“缺少分隔符”意味着您可能没有在 CC 或 rm 行中使用制表符。尝试按如下方式重新格式化文件。Make
很挑剔,因为所有命令行都必须以制表符开头。不是 4 个空格,不是 8 个空格,而是一个实际的制表符 (ASCII 0x09)。
"Missing separator" means you probably didn't use a tab character in your CC or rm lines. Try reformatting the file as follows
Make is picky in that all command lines must lead with a tab character. Not 4 spaces, not 8 spaces, but an actual tab (ASCII 0x09).
除了缩进问题之外,您还应该从 CFLAGS 中删除
-c
,否则生成的 hello 将不是可执行文件,而是一个没有正确名称的 .o 文件。In addition to indentation problems, you should drop
-c
from CFLAGS, else the produced hello will not be an executable but a .o file without the correct name.