以hello_test.c文件为例
1.创建程序
在linux控制台界面下 ,输入vi hello_test.c,输入i进入编辑插入模式,输入代码如下:
#include <stdio.h>
int main(void)
{
printf("Hello,Word!/n");
return 0;
}
用gcc编译程序
输入命令:gcc hello_test.c
输入命令:ls
显示:a.out hello_test.c
输入命令:./a.out //执行程序
2.使用Makefile
(1)创建Makefile,在hello_test.c所在目录输入 vi Makefile
(2)输入Makefile内容。在vi插入模式下输入:
hello_test : hello_test.c
gcc -o hello_test hello_test.c //特别注意 gcc前面不是空格,而是tab间隔符,否则会出现 makefile:2: *** 遗漏分隔符错误
clean :
rm -fr hello_test *.o *.core
(3)输入make,屏幕输出 gcc -o hello_test hello_test.c,表示编译已经通过。生成 hello_test.