![]() |
|||
| 隨手行文 | 閒語集 | 過客留言 | 飛鴿傳書 | |||
作者: 遊手好閒的石頭成
E-Mail: shirock@pchome.com.tw
Mingw32 是一套以 Gnu gcc/egcs 計劃為基礎的編譯器,其可編譯出在 Win32 系統上執行的 ojbect code。
"Mingw32" 是取 Minimalist Gnu-Win32 計劃之意,其目標為提供一個可在 Win32 平台上,開發 Win32 native code 的編譯器,而非提供 unix 程式移植到 Win32 平台之用,此即為其 minimalist 之意。
ps. Mingw32 是開發原生 Win32 程式用的,如果想要移植即有的 unix 程式, 不應使用 Mingw32 ,建議採用 Cygnus 的 Cygwin 或 AT&T 的 UWin 。
Mingw32 使用 Microsoft runtime libraries ,因此由其產生之程式,執行時不需先行安裝其他的 DLL 。 此外,其提供 Win32 API 的 header ,故可在程式中呼叫 Win32 API ,並相當程度地相容於 MS Visual C++ binary ,可以使用 VC++ 的 libraries ,也支援部份的 COM 。
理論上, Mingw32 可使用 Win32 系統上的各式 Software Develope Toolkit ,例如 DirectX 便已經證實可行。
Mingw32 提供兩種 Microsoft runtime libraries 版本,一是 Ctrdll.dll ,另一為 Msvcrt.dll 。
Ctrdll.dll 存在於所有的 Win32 系統上,甚至在 Windows 3.11/Windows NT 3.5 等 Win32s 系統上亦有,但是很久沒有更新了。
Msvcrt.dll 則為較新且持續進行更新與增添功能的 runtime library ,其存在於較新的 Win32 系統上,簡單的分辨方式為,如果該電腦上有安裝 IE4 或以上的版本時,便有 Msvcrt.dll 。
Mingw32 主要以 Ctrdll.dll 為測試目標,故採用 Ctrdll.dll 的版本較穩定。
GCC 2.95.2 and associated development tools for Mingw32/MSVCRT.
先行閱讀其 README.TXT 及 INSTALL.TXT ,知道各安裝步驟,並了解什麼是 Mingw32 。 我是裝在 Windows 95 的系統下。
執行 gcc-2.95.2-msvcrt.exe ,指定存放目錄,解壓縮後,即完成初步安裝。
例如放在 "C:\Program Files\Mingw32" 。
接著開啟存放目錄,修改 mingw32.bat 中的 PATH 及 GCC_EXEC_PREFIX 之內容。
例如:
PATH=%PATH%C:\PROGRA~1\MINGW32\bin; SET GCC_EXEC_PREFIX=C:\PROGRA~1\MINGW32\lib\gcc-lib\
最後,為了方便執行,在桌面或開始功能表中,建立一個捷徑:
指令行: c:\ command.com
批次檔: your_mingw32_path\mingw32.bat
ps. 做為程式開發人員,應該知道上述兩行該用在捷徑的何處?
執行該捷徑後,會啟動一個 MS-DOS 視窗,此時在該視窗中, 即可下指令執行 gcc 及其工具。
由於我另外還有安裝 Cygwin B20.1 ,為了隔離此兩者, 我並沒有將 mingw32.bat 中的設定,寫在 autoexec.bat 中。
若系統中只有 GCC/Mingw32 ,則可以將設定寫在 Autoexec.bat 中, 如此一來,就可在任何情形下執行 gcc 及其工具。
在 gcc-2.95.2-msvcrt.exe 中,缺少 grep, diff, gzip, gunzip, bison, flex, m4, 等 unix 程式發展者常用工具,不過皆可另行取得他人為 Mingw32 所移植好的上述程式之檔案來安裝。
通常我是將 grep, diff, gzip 放在 "C:\Program Files\bin32" 下,並將該路徑寫在 Autoexec.bat 的 PATH 設定中,以便在各種情形下,皆能使用。
關於 Mingw32 的使用資訊,可查閱其網頁的 FAQ 文件( mingw32.htm )。
Mingw32 網頁: http://www.xraylith.wisc.edu/~khan/software/gnu-win32/
底下為兩個 FAQ 中所附的範例程式。
#include <stdio.h>
int main(int argc, char **argv)
{
printf ("Hello\n");
return (0);
}
C:> gcc -o hello hello.c
#include <windows.h>
int WINAPI WinMain (HINSTANCE hInstance,
HINSTANCE hPrevInstance,
PSTR szCmdLine,
int iCmdShow)
{
MessageBox (NULL, "Hello", "Hello Demo", MB_OK);
return (0);
}
C:> windres -o resfile.o resfile.rc
C:> gcc -o hello hello.c resfile.o -mwindows
遊手好閒的石頭成 ( shirock@pchome.com.tw )
|
Copyright (c) Shih Yuncheng <shirock@educities.edu.tw>. Rock's saying: http://home.educities.edu.tw/shirock/ Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation; with the Invariant Sections being LIST THEIR TITLES, with the Front-Cover Texts being LIST, and with the Back-Cover Texts being LIST. A copy of the license is included in the section entitled "GNU Free Documentation License". http://www.fsf.org/licenses/fdl.html |
| 隨手行文 | 閒語集 | 過客留言 | 飛鴿傳書 | 石頭閒語 (http://home.educities.edu.tw/shirock/) |
| Copyright (C) 1999 - 2002 遊手好閒的石頭成 | 更新日期: 2000年 2月21日 |