Try   HackMD

安裝 Mingw-w64 教學

Download and install Mingw-w64 on Win10 tutorials

tags:c/c++

關於MinGW

下載 MinGW-w64 安裝執行檔

  1. 進入官方網站 Officical Website
  2. 進入網站後,頁面大概如下,點選紅框
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  3. 首先會看到 "Pre-built toolchains and package" 的表格,這裡是包含MinGW-w64及特定工具整合包。本教程只專注於安裝MinGW-w64,所以僅下載MinGW-w64即可。找到 "Souces" 標題,並點選紅框
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  4. 進入SourceForge頁面後,會看到很多檔案,這邊如果沒有特殊需求的話,直接點擊藍框後,找到 "MinGW-W64 Online Installer" 點擊紅框,或直接下拉頁面找到紅框部分。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  5. 在等待5秒鐘後,該執行檔就會自動下載至本機端。

安裝MinGW-w64

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →
若出現執行檔不能執行的錯誤,也可以直接下載對應的壓縮檔 x86_64-win32-seh,解壓縮後即可使用。

  1. 在本機端找到該執行檔 "mingw-w64-install.exe"。開啟後下一步到以下畫面。筆者設定如下,接著點選紅框
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

Version: gcc版本。沒有特殊需求,一般選擇最新版本號。
Architecture: 電腦系統架構。

  1. 64位元: x86_64
  2. 32位元: i686

Threads: 這邊筆者比較沒概念。可參考大神的解釋。
Exception:異常處理模型。

  1. seh性能較優,但不支援32位元。
  2. sjlj效能較差,支援32位元和64位元。

Build version: 這邊沒得選,維持默認。

  1. 接下來可更改安裝位置藍框。筆者這邊選擇默認位置(稍微記下這個位置,後面會用到),點選紅框
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  2. 這邊就讓它進行自動安裝流程。這邊會根據網路速度而定,筆者實測大約5分鐘。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  3. 這樣就安裝完成啦
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    !
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

設定環境變數

  1. 到剛剛的安裝目錄,會看到以下的檔案,點選紅框
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  2. 再次點選紅框
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  3. 在這個資料夾內存放許多的執行檔。如綠框部分,gcc.exe是編譯C語言,g++.exe是編譯C++,而gdb.exe是偵錯(debug)時的工具。點擊紅框,並複製藍色文字
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  4. 於左下角 "開始" 右鍵,點選 "系統"
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  5. 進入畫面後點選右側 "進階系統設定"(即紅框部分)。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  6. 再點擊紅框
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  7. 接著找到 "Path" 並點擊,再按 "編輯"。註:如果想要讓此電腦的所有使用者皆可使用,則更改 "系統變數" (即下方選單),步驟相同。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
  8. 點選 "新增",再將剛剛複製的路徑貼上,最後按下 "確定" 就完成了。
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

安裝與環境變數設定完成

  • 可透過在 "命令提示字元" (搜尋cmd)輸入以下指令,如有成功輸出版本資訊,就是安裝成功啦
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →
    !
    ​​​​gcc -v
    ​​​​g++ -v
    
    示意圖如下
    Image Not Showing Possible Reasons
    • The image file may be corrupted
    • The server hosting the image is unavailable
    • The image path is incorrect
    • The image format is not supported
    Learn More →

Vscode 中使用 C/C++

可以參考專案VSCode_template_for_c_cpp