mingw-get-setup.exe 在線安裝器)。mingw32-gcc-g++、mingw32-base 等基本套件。bin 資料夾(如 C:\MinGW\bin)加入系統環境變數 Path。
bin 目錄建立 test.cpp:#include <iostream>
int main() { std::cout << "Hello GCC" << std::endl; return 0; }
test.bat,內容:gcc test.cpp。test.bat,目錄下產生 a.exe,執行顯示 Hello GCC 即成功。| 參數 | 說明 | 範例 |
|---|---|---|
-o <name> | 指定輸出執行檔名稱 | gcc -o myapp test.cpp → 產生 myapp.exe |
-E | 僅預處理,輸出至標準輸出(大寫 E) | gcc -E test.cpp > test.i |
-S | 編譯至組合語言 .s | gcc -S test.cpp |
-c | 編譯至目標檔 .o,不連結 | gcc -c test.cpp |
-Wall | 開啟大多數警告 | gcc -Wall test.cpp |
-O2 | 優化等級 2(速度/大小平衡) | gcc -O2 test.cpp |
gcc: no input files:參數大小寫錯誤(如 -e 應為 -E),或未指定來源檔。command not found:Path 未正確加入 bin 目錄,重開終端機生效。mingw32-libxxx。實際專案建議使用 CMake 或 Makefile 管理建置流程,避免手動指令繁瑣。