MinGW:安裝gcc、g++
1.MinGW是什麼?
wiki:https://en.wikipedia.org/wiki/MinGW
MinGW (“Minimalist GNU for Windows”), formerly mingw32, is a free and open source software development environment to create Microsoft Windows applications.
簡單來說,MinGW是一系列工具集合,包括類似yum、rpm的庫/包管理功能。
The development of the MinGW project has been forked with the creation in 2005–2008 of an alternative project called Mingw-w64.
MinGW有一個fork版本,即Mingw-w64。(同時支援32bit和64bit)
MinGW includes a port of the GNU Compiler Collection (GCC), GNU Binutils for Windows (assembler, linker, archive manager), a set of freely distributable Windows specific header files and static import libraries which enable the use of the Windows API, a Windows native build of the GNU Project’s GNU Debugger, and miscellaneous utilities.
MinGW包括的内容,有gcc編譯器、連結器、頭檔案等。
MinGW can be run either on the native Microsoft Windows platform, cross-hosted on Linux (or other Unix), or “cross-native” on Cygwin. Although programs produced under MinGW are 32-bit executables, they can be used both in 32 and 64-bit versions of Windows.
注意:基于MinGW生成的可執行檔案都是32bit的。
2.MinGW怎麼裝?
2.1.安裝目錄
D:\app\MinGW
2.2.下載下傳檔案
https://sourceforge.net/projects/mingw/
mingw-get-setup.exe
2.3.安裝 MinGW Installation Manager
注意,選擇安裝目錄為:D:\app\MinGW
安裝中…
點選:Continue
安裝成功後,将會自動打開 MinGW Installation Manager:
此時,MinGW/bin中僅有mingw-get.exe。
[email protected] MINGW64 /d/app
$ ll MinGW/
total 0
drwxr-xr-x 1 EB 197609 0 Jun 22 14:58 bin/
drwxr-xr-x 1 EB 197609 0 Jun 22 14:58 libexec/
drwxr-xr-x 1 EB 197609 0 Jun 22 14:58 share/
drwxr-xr-x 1 EB 197609 0 Jun 22 14:58 var/
[email protected] MINGW64 /d/app
$ ll MinGW/bin
total 52
-rwxr-xr-x 1 EB 197609 52224 Oct 5 2013 mingw-get.exe*
2.4.安裝 gcc、g++等庫/包
選中所有的package:
點選左上角Installation:Apply Changes,進行安裝:
安裝完成,關閉對話視窗:
此時,MinGW\bin中包含我們常見的:
c++.exe、cpp.exe、g++.exe、gcc.exe、gdb.exe、ld.exe、nm.exe、objdump.exe等等。
$ ll c++.exe cpp.exe g++.exe gcc.exe gdb.exe ld.exe nm.exe objdump.exe
-rwxr-xr-x 1 EB 197609 997902 May 30 2017 c++.exe*
-rwxr-xr-x 1 EB 197609 996366 Jul 25 2017 cpp.exe*
-rwxr-xr-x 1 EB 197609 997902 May 30 2017 g++.exe*
-rwxr-xr-x 1 EB 197609 995342 Jul 25 2017 gcc.exe*
-rwxr-xr-x 1 EB 197609 30595068 Sep 15 2013 gdb.exe*
-rwxr-xr-x 1 EB 197609 1291278 May 22 2017 ld.exe*
-rwxr-xr-x 1 EB 197609 978958 May 22 2017 nm.exe*
-rwxr-xr-x 1 EB 197609 1756174 May 22 2017 objdump.exe*
2.5.配置環境變量PATH
将D:\app\MinGW\bin添加到環境變量PATH中:
控制台\系統和安全\系統->進階系統設定->環境變量->使用者變量->編輯變量PATH:
新增路徑D:\app\MinGW\bin,然後确認儲存即可。
3.MinGW測試使用
Microsoft Windows [版本 10.0.17763.107]
(c) 2018 Microsoft Corporation。保留所有權利。
C:\Users\EB>where gcc g++
D:\app\MinGW\bin\gcc.exe
D:\app\MinGW\bin\g++.exe
C:\Users\EB>gcc --version
gcc (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
C:\Users\EB>g++ --version
g++ (MinGW.org GCC-6.3.0-1) 6.3.0
Copyright (C) 2016 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
4.MinGW安裝常見問題?
4.1.報錯1
mingw-get: *** ERROR *** http://prdownloads.sourceforge.net/mingw/mingw-get-0.6.2-mingw32-beta-20131004-1-bin.tar.xz?download:cannot open URL
解決方法:科學上網。
4.2.報錯2
解決方法:科學上網。