make:***没有规则来制作'全部'所需的目标`gcc'。停止

时间:2011-12-19 09:05:01

标签: c makefile

我正在通过例如pgm来创建一个make文件。

http://mrbook.org/tutorials/make/

我的文件夹eg_make_creation包含以下文件

desktop:~/eg_make_creation$ ls
factorial.c  functions.h  hello  hello.c  main.c  Makefile

生成文件

all:gcc -c main.c hello.c factorial.c -o hello

错误:

desktop:~/eg_make_creation$ make all
make: *** No rule to make target `gcc', needed by `all'.  Stop.

请帮助我理解编译这个程序。

4 个答案:

答案 0 :(得分:14)

makefile的语法非常严格:

target:dependencies
        build_rules
# ^ this space here _needs_ to be a tab.

您撰写的内容all取决于gcc-c,...这些都不是有效目标。

您需要的是:

all: hello

hello: factorial.c  functions.h hello.c  main.c 
         gcc -o hello factorial.c hello.c  main.c 

(如果您想一步编译和链接,请不要使用-c开关。)

答案 1 :(得分:1)

Mat钉了它。

在我的特定情况下,我正在使用vi并默认启用expandtab !!

要查看此问题是否适用于您,请打开vi并执行:

:set list

如果你没有看到选项卡所在的^ I,那么你很可能已启用了et。

要禁用它:

:set expandtab!

也许它也有助于其他人。

答案 2 :(得分:0)

另一个原因是因为源文件列表中的名称错误。 (nameWrong.o而不是nameRight.o)这是我的问题。

答案 3 :(得分:0)

After all:一切都是目标,显示依赖于之后写入的任何内容应该呈现该目录,就像你的代码gcc(因为文件不存在)一样明智-c all:gcc -c main.c hello.c factorial.c -o hello正确的是 all:main.c hello.c factorial.c -o hello 请阅读更多相关信息GNU MAKE