2012年4月25日 星期三

安裝 C++ Compiler 編譯環境


G++ Compiler windows 安裝環境:

1. 至 MinGW 網站, 選擇 Download -> Installer -> mingw-get-inst -> mingw-get-inst-20120421
2. 下載 mingw-get-inst-20120421.exe
3. 執行 mingw-get-inst-20120421.exe, 選擇 Download latest repository catalogues
4. Select Components 選項中, 加選 C++ Compiler
5. 安裝完後, 新增 hello.cpp 檔案, 輸入以下程式:


// hello.cpp

#include <iostream> // Basic input and output library

int main() {
    std::cout << "Hello World\n";
    return 0; // Return to the operating system
}



6. 執行 C:\MinGW\bin\g++.exe hello.cpp -o hello
   出現: cc1plus.exe - 找不到元件, 這個應用程式無法啟動,因為找不到 libgmp-10.dll,
   重新安裝應用程式可能可以解決這個問題。

7. 如果出現步驟 6 的狀況, 請再到 MinGW 網站, 下載 mingw-get-inst-20111118.exe 檔案.
   下載完後, 重新安裝, 應該就會發現 C:\MinGW\bin 下面有 libgmp-10.dll 的檔案.

8. 設定環境變數 path, 我的電腦 -> 按滑鼠右鍵 -> 內容 -> 進階 -> 環境變數 -> 系統變數 -> Path -> 編輯
   -> 在最後分號處, 加入 C:\MinGW\bin;

9. 如果要編譯 Windows 的程式, 可以執行如下指令:
   C:\MinGW\bin\g++.exe sample01.cpp -o sample01 -mwindows -Wall

1 則留言:

健力宝 提到...

感谢您的文章解决了我的问题。

谢谢!