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。