首先準備一個源碼文件 hello.cspa
鍵入以下代碼:code
#include <stdio.h> int main() { /* 個人第一個 C 程序 */ printf("Hello, World! \n"); return 0; }
cd到源碼所在路徑blog
gcc 源碼文件名源碼
輸入回車,編譯代碼io
若是代碼中沒有錯誤,命令提示符會跳到下一行,並生成 a.out 可執行文件編譯
鍵入 a.out 來執行程序class
$ gcc hello.c $ ./a.out Hello, World!
若是是多個c代碼的源碼,編譯方法以下:test
$ gcc test1.c test2.c -o main.out $ ./main.out