Windows安裝MinGW / MinGW-w64 === 這裡會介紹兩個方法來安裝MinGW,分為有Installer 和無Installer,想要懶人安裝的可以選擇前者,若是有其它需求,或想要手動選擇版本,可以選擇後者。這篇主要會講解無Installer的安裝方法,也是為了下一篇在VSCode環境下設置C++的OpenCV做準備。 ## 兩者差異 :::info Installer的MinGW是Win32版本,使用了native Win32 threading functions, 本文介紹的MinGW-w64是posix版本的,基於winpthreads(Windows版pthreads),兩者在特性上會有差別。一般使用前者就足夠,但若有其它需求,如C11支持的\<thread>, \<mutex>, 或\<future>,就要使用posix版MinGW-w64。 ::: [What is Pthreads](https://en.wikipedia.org/wiki/Pthreads) [Linux pthreads manual](https://man7.org/linux/man-pages/man7/pthreads.7.html) [Pthreads-w32](vhttps://sourceware.org/pthreads-win32/),一個早期用來解決在Win32上沒有辦法使用pthreads的資源,但現在好像已經沒有繼續維護了。 ## 方法一:Installer #### Step1. 在 [SourceForge](https://sourceforge.net/projects/mingw/) 下載 setup tool  下載好的檔案應該會長這樣:  #### Step2. `mingw-get-setup.exe`,點擊 **install**。  之後就一路 **continue**,默認安裝在 `C:\MinGW` 接著會進入 **Installation Manager** 介面,如下:  右鍵選擇 **mingw32-base** 和 **mingw32-gcc-g++**,然後選左上角**Installation下拉選單**,點擊 **Apply Changes**,編譯C和C\++的工具就會開始下載啦~  >[!Tip] > 如果有其它package的需求,可自行勾選。 全部完成後,可以看到`C:\MinGW\bin`裡多了很多檔案,其中包含gcc.exe和g++.exe這兩個用來編譯C和C\++的執行檔。 前: 後: #### Step3. 設定**環境變數 System Environment Variables** System > About > Device specifications > Advanced system settings > Environment Variables > User Variables for xxx > Path > New > Enter `C:\MinGW\bin` 中文版的設定也大同小異,各位就自行理解和翻譯啦~  >[!Note] 註 > 如果電腦有多個users,又不想設定System Variables,就使用User Variables設定。 到這裡,MinGW的設定就全部完成了,這時候打開Terminal或CMD,輸入`gcc --version`或`g++ --version`,出現這樣的畫面代表安裝成功了,就可以開始編譯了!  ## 方法二:無Installer 這個方法是直接從MinGW-w64的github下載完整的執行檔、編譯器和相關函式庫,不需要像方法一那樣要自行選擇要下載的工具。 #### Step1. 下載 MinGW64 seh壓縮檔 從 [GitHub Releases](https://github.com/niXman/mingw-builds-binaries/releases) 下載  點進去之後可以看到不同的配置組合,在早一點的`12.2-rev1`版本沒有分ucrt和msvcrt,有興趣了解可以參考以下網址: >[!Note]參考鏈接 >mscvrt vs ucrt: [Differences between msvcrt, ucrt and vcruntime libraries](https://stackoverflow.com/questions/67848972/differences-between-msvcrt-ucrt-and-vcruntime-libraries) >sjlj、dwarf、seh異同:https://blog.csdn.net/AMDDMA/article/details/111600238 這裡我選擇的是`14.2`這個版本,也可以下載最新版本的`15.2`。 >[!Important] 小貼士 >通常不建議下載最新版本的,可能會有各種兼容問題。 選擇`x86_64-14.2.0-release-posix-seh-ucrt-rt_v12-rev0.7z`,然後下載。 #### Step2. 解壓縮 解壓縮後會得到`mingw64`的資料夾,可以自由選擇要放在哪裡,以本文為例,是放在`C:\opt\`的資料夾內,所以最後`mingw64`的路徑會是`C:\opt\mingw64\`  #### Step3. 配置環境變數 這一步跟方法一的步驟3一樣,但若路徑名稱有更改,記得要更新。  打開Terminal/CMD測試,可以跑起來,就是安裝成功咯!  ## 後記 一開始用C/C++的時候由於沒有特殊需求,所以就用方法一安裝,用的都很順利,直到最近需要OpenCV,所以就改用方法二。至於為什麼不用Python的OpenCV,請聽下回揭曉。 ## 參考來源 * [windows+Cmake+MinGW+编译opencv4.5 sources安装过程以及opencv踩坑日记](https://blog.csdn.net/qq_42218706/article/details/132377836) * [MinGW-64-bit](https://wiki.qt.io/MinGW-64-bit)
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up