GCC 全名為 GNU Compiler Collection,是 GNU 計劃製作的一種最佳化編譯器,支援各種程式語言、作業系統、電腦系統結構。
該編譯器是以 GPL 及 LGPL 授權條款所發行的自由軟體,也是 GNU 計劃的關鍵部分,還是 GNU 工具鏈的主要組成部份之一。
GCC(特別是其中的 C 語言編譯器)也常被認為是跨平台編譯器的事實標準。
而 GCC 的原名為 GNU C 語言編譯器(GNU C Compiler),因為它原本只能處理 C 語言。
Windows 10 x64 安裝 GCC
1. 到 MinGW 網站下載 mingw‑get‑setup。
2. 執行 mingw-get-setup.exe 安裝檔工具。按 Install 進行安裝。
![[Windows 10] Installing GCC on [Windows 10] Installing GCC on](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/mitblog/1676135879-1747710394-g.png&ver=20250714)
3. 點選 Continue。
![[Windows 10] Installing GCC on [Windows 10] Installing GCC on](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/mitblog/1676136241-1977090840-g.png&ver=20250714)
4. 安裝進行中。
![[Windows 10] Installing GCC on [Windows 10] Installing GCC on](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/mitblog/1676136399-1802051743-g.png&ver=20250714)
5. 勾選 mingw32-base-bin、mingw32-gcc-g++-bing 項目,按 Apply Changes。
![[Windows 10] Installing GCC on [Windows 10] Installing GCC on](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/mitblog/1676137906-2934822430-g_l.png&ver=20250714)
6. Download Package.
![[Windows 10] Installing GCC on [Windows 10] Installing GCC on](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/mitblog/1676138104-2059081717-g.png&ver=20250714)
7. 按 Apply。
![[Windows 10] Installing GCC on [Windows 10] Installing GCC on](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/mitblog/1676138273-402138385-g_l.png&ver=20250714)
8. 套用變更中。
![[Windows 10] Installing GCC on [Windows 10] Installing GCC on](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/mitblog/1676138389-1916545386-g.png&ver=20250714)
9. 套用完後的畫面。
![[Windows 10] Installing GCC on [Windows 10] Installing GCC on](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/mitblog/1676138554-2928421843-g.png&ver=20250714)
10. 開啟 Windows 內建的命令提示字元 cmd。輸入 gcc 和 g++ 指令,測試 gcc 和 g++ 是否成功。出現找不到 gcc 和 g++ 命令。
Microsoft Windows [Version 10.0.22621.1194] (c) Microsoft Corporation. All rights reserved. C:\Users\mitblog>gcc 'gcc' is not recognized as an internal or external command, operable program or batch file. C:\Users\mitblog>
或,輸入 g++ --version 指令。
Microsoft Windows [Version 10.0.22621.1194] (c) Microsoft Corporation. All rights reserved. C:\Users\mitblog>g++ --version 'g++' is not recognized as an internal or external command, operable program or batch file. C:\Users\mitblog>
或,輸入 gcc --version 指令。
Microsoft Windows [Version 10.0.22621.1194] (c) Microsoft Corporation. All rights reserved. C:\Users\mitblog>gcc --version 'gcc' is not recognized as an internal or external command, operable program or batch file. C:\Users\mitblog>
11. 為了解決步驟 9 的問題,要在環境變數的 Path 加入 C:\MinGW\bin 路徑。
![[Windows 10] Installing GCC on [Windows 10] Installing GCC on](https://imageproxy.pixnet.cc/imgproxy?url=https://pic.pimg.tw/mitblog/1676139663-2796093755-g.png&ver=20250714)
12. 重開 Windows 命令提示字元視窗,再次輸入 gcc 和 g++ 指令,測試 gcc 和 g++ 成功。
Microsoft Windows [Version 10.0.19043.928] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\mitblog>gcc gcc: fatal error: no input files compilation terminated. C:\Users\mitblog>
或,輸入 g++ --version 指令。
Microsoft Windows [Version 10.0.19043.928] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\mitblog>g++ --version g++ (MinGW.org GCC Build-2) 9.2.0 Copyright (C) 2019 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.
或,輸入 gcc --version 指令。
Microsoft Windows [Version 10.0.19043.928] (c) 2019 Microsoft Corporation. All rights reserved. C:\Users\mitblog>gcc --version gcc (MinGW.org GCC Build-2) 9.2.0 Copyright (C) 2019 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.
13. 使用記事本建立 hello.txt 簡單的 C 程式碼,並將附檔名改為 .c。
//This is my first C program
#include <stdio.h>
int main()
{
printf("Hello I am your Computer and I can do this that you can't\n");
return 0;
}
14. 執行指令進行編譯。
C:\c program>gcc hello.c -Wall -o hello
15. 會產生一個 hello.exe 執行檔。
C:\c program>hello.exe Hello I am your Computer and I can do this that you can't
Reference:https://www.youtube.com/watch?v=78j-Gvx2MP0
留言列表
