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

Ang*_*gus 4 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
Run Code Online (Sandbox Code Playgroud)

Makefile文件

all:gcc -c main.c hello.c factorial.c -o hello
Run Code Online (Sandbox Code Playgroud)

错误:

desktop:~/eg_make_creation$ make all
make: *** No rule to make target `gcc', needed by `all'.  Stop.
Run Code Online (Sandbox Code Playgroud)

请帮我理解编译这个程序.

Mat*_*Mat 14

makefile的语法非常严格:

target:dependencies
        build_rules
# ^ this space here _needs_ to be a tab.
Run Code Online (Sandbox Code Playgroud)

你写的是什么使得all取决于gcc,-c,...是不是有效的目标.

你需要的是:

all: hello

hello: factorial.c  functions.h hello.c  main.c 
         gcc -o hello factorial.c hello.c  main.c 
Run Code Online (Sandbox Code Playgroud)

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