Linux_C_Program

Linux C 编程-makefile 文件 要在每个命令前要加TAB

最近在学 Linux C 编程,编写了以下test.c文件,

/*文件   test.c*/
#include   “stdio.h”

int   main()
{
printf(“Hello   world!\n”);
}

#文件:   makefile
test:test.o
gcc   -o   test   test.o
test.o:test.c
gcc   -c   test.c

当我在当前目录下 执行   make    ,
shell  提示错误:   makefile:4:   ***   missing   separator.     Stop.
我查资料得知:
missing   separator
如下的错误信息:
makefile:2:missing   separator.   Stop.
或:
makefile:2:missing   separator   (did   you   mean   TAB   instead   of   8   spaces?).   Stop.
通常代表你的命令脚本以空格代替了跳格。
以文字来解释的话,就是make   想要查找一个make   分隔符,比如:、=   或一个跳格符,
但是找不到。它所找到的是它不了解的东西。

但我不明白   makefile   里哪里需要使用   Table   时我用的   space   。

我到谷歌网站Google了一下,发现 在makefile 文件里每个命令前要加TAB。

即是

#文件:   makefile

test:test.o
[TAB]gcc   -o   test   test.o
test.o:test.c
[TAB]gcc   -c   test.c

保存后,重新执行make命令,

使用ls命令会发现当前文件夹多了一个test可执行文件。

在shell中执行./test  ,运行test文件

可得结果:

Hello,World!

END