2019年7月4日 星期四

在Windows 使用gcc - Cygwin


官方網址

http://www.cygwin.com/

Cygwin 可以讓我們在Windows 上執行Liunx或Unix-like的軟體,包含gcc。

要搭建基本的gcc C/C++開發環境,除本身預設安裝的套件外,需額外安裝幾個套件
  Categories    Package     Description  
Develgcc-coreGNU Compiler Collection (C, OpenMP)
Develgcc-g++GNU Compiler Collection (C++)
DevelmakeThe GNU version of the 'make' utility
Develbinutils GNU assembler, linker and similar utility
Develgdb The GNU debugger


test.c

#include <stdio.h>
int main() {
  printf("Hello World!\n");
  return 0;
}


編譯test.c並輸出test.exe
$ gcc test.c -o test

執行test.exe
$ ./test.exe
Hello World!


在Cygwin上安裝新的套件


1. 執行原本安裝時所使用的安裝檔(如果遺失就直接重新下載)。


2. 選擇"Download Without Installing",只下載套件不安裝。並在「Select Local Package Directory」的頁面中選擇之前安裝套件所使用的資料夾。


3. 接著選擇需要的套件下載。

4. 下載完成後,再執行Cygwin安裝檔,選擇"Install from Local Directory"來從下載好的套件安裝。

5. 在「Select Root Install Directory」選擇先前Cygwin所安裝的路徑。並一樣在
「Select Local Package Directory」的頁面中選擇之前安裝套件所使用的資料夾,
之後找到所選擇的套件進行安裝即可。

2021/07/02 Note: 安裝新套件的步驟2可直接選擇"Install from Internet",相當於步驟3到5。