学习C艰难的练习2

时间:2013-06-28 17:36:40

标签: makefile

我刚开始学习C艰难的方式,我正在练习#2。

链接到这里: http://c.learncodethehardway.org/book/ex2.html

说明是制作一个只包含此文件的文件:

    CFLAGS=-Wall -g

    clean:
       rm -f ex1

所以我创建并保存为Makefile.c,但是,在我的编译器(MINGW)中指定运行它时,我收到此错误:

$make clean
cc    makefile.c    -o makefile
makefile.c:3:1: warning: data definition has no type or storage class [enabled by default]
makefile.c:3:9: error: 'Wall' undeclared here (not in a function)
makefile.c:3:15: error: 'g' undeclared here (not in a function)
makefile.c:5:1: error expected ',' or ';' before 'clean'
cc    Makefile.c    -o Makefile
Makefile.c:3:1: warning: data definition has no type or storage class [enabled by default]
Makefile.c:3:9: error: 'Wall' undeclared here (not in a function)
Makefile.c:3:15: error: 'g' undeclared here (not in a function)
Makefile.c:5:1: error expected ',' or ';' before 'clean'
make: *** No rule to make target 'clean'. Stop.

任何想法我做错了和/或我如何解决这个问题?谢谢!

3 个答案:

答案 0 :(得分:3)

迟到了,但你的makefile应该只是命名为“Makefile”

Makefile不是C程序的源代码,而是Makefile工具的一组指令,在您输入“make foo”时会使用它。

答案 1 :(得分:1)

Makefile可以被称为“makefile”或“Makefile”

据男人说:

  

“通常你应该把你的makefile调成makefile或Makefile。(我们推荐使用Makefile,因为它突出显示在目录列表的开头附近,就在其他重要文件如README附近。)检查的第一个名字,GNUmakefile,不是推荐用于大多数makefile。“

答案 2 :(得分:0)

您使用制表符而不是空格吗?网页有空格,但makefile需要标签。请注意makefile代码后作者的注释。