初學者在 Linux 進行 C 開發,建議先用 VMware 虛擬機雙系統共存,熟練後再考慮裸機。Ubuntu 安裝便捷 (Windows 內安裝/移除)、介面美觀是首選。
用 gedit 建立 hello.c:
main() {
printf("Hello, Linux!");
}
副檔名必須 .c,否則無法識別。
gcc hello.c -o hello
./hello
# 輸出:Hello, Linux!
編譯可能出現警告:implicit declaration of function 'printf',初學者易誤以為缺 glibc,實際只需包含頭文件。
#include
int main() {
printf("Hello, Linux!\n");
return 0;
}
再次 gcc hello.c -o hello 警告消失,執行正常。
多源文件/頭文件專案需引入 Makefile 管理編譯流程,建議後續深入學習。