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