Chinaunix首页 | 论坛 | 博客
  • 博客访问: 5705395
  • 博文数量: 675
  • 博客积分: 20301
  • 博客等级: 上将
  • 技术积分: 7671
  • 用 户 组: 普通用户
  • 注册时间: 2005-12-31 16:15
文章分类

全部博文(675)

文章存档

2012年(1)

2011年(20)

2010年(14)

2009年(63)

2008年(118)

2007年(141)

2006年(318)

分类:

2006-09-01 19:26:07

MinGW - Minimalist GNU For Windows

Mingw32 是 GNU 計畫工具的集合,包含了大量的標頭檔(header files)、函式庫與指 令程式。目的在提供免費的工具以生產製作可於 Winodws 上直接執行而無須依賴輔助函式 庫的原生程式(Native Windows programs)。

在 Debian 系統中,您可以安裝 、 與 三個套件軟體。

  • - Minimalist GNU win32 (cross) compiler 包含 win32 跨平台編譯器
  • - Minimalist GNU win32 (cross) binutils 包含 win32 跨平台指令集
  • - Minimalist GNU win32 (cross) runtime 函式庫及標頭檔

包含的就是 g++(c++,cpp)、gcc(cc)、gcov、gccbug 等必備的 win32 跨平台編譯器,您需要這些編譯器產生可在 Microsoft Windows 上使用的 exe、dll 檔案等。 則是 nm、strip、ar、ranlib、dlltool、as、ld、windres、addr2line、size、objdump、readelf 等,在產生原生程式時必要的工具。這些指令為了與原生編譯器有所區別,目錄與其他軟體大不相同,擺在 /usr/i586-mingw32msvc/ 中。指令命名原則也以 i586-mingw32msvc 開頭。

例如產生一個 console executable 執行檔。

user@debian:~$ cat hello.cpp
#include
int main(int argc, char* argv[])
{
std::cout << "Hello world\n";
return 0;
}
user@debian:~$ i586-mingw32msvc-g++ -o hello.exe hello.cpp
user@debian:~$ file hello.exe
hello.exe: MS Windows PE 32-bit Intel 80386 console executable not relocatable

如果你安裝了 ,你甚至可以直接執行它。由於 配合 使用,因此你的系統應該懂著識別 .exe 檔案,並以 執行他。

user@debian:~$ ./hello.exe
Hello world
Wine exited with a successful status

或者編譯一個顯示一個訊息窗的圖形化使用者介面程式

user@debian:~$ cat > hello.cpp
#include
int WINAPI WinMain(HINSTANCE d1, HINSTANCE d2, LPSTR d3, int d4)
{
MessageBox(NULL, "Hello, World!", "", MB_OK);
return(0);
}
user@debian:~$ i586-mingw32msvc-g++ -o hello.exe hello.cpp -mwindows
user@debian:~$ file hello.exe
hello.exe: MS Windows PE 32-bit Intel 80386 GUI executable not relocatable

您大概注意到指令中新增了 "-mwindows" 參數,這是用來建立 "Windows Application" 而非 "Console Application",並在連結(linking) 過程中確保使用 Windows 函式庫。上述 我們只顯示 "Hello World" 字串的範例中,便是所謂的 "Console Application",執行時 會啟動一個主控台(Console)視窗。您可以加上 " -mconsole" 以編譯為 "Console Application"。

透過 mingw32 的協助,您可以在 Linux 系統上設計 "Write Once, Run Everywhere" 的 C / C++ 程式,例如在 Linux 平台編譯同時支援 Unix 、 Mac 與 Windows 的 。

取自""

本頁面已經被瀏覽2,126次。 最後更改10:02 2005年七月14日. 本站所有內容允許以下方式利用: GNU Free Documentation License 1.2

阅读(4992) | 评论(4) | 转发(0) |
给主人留下些什么吧!~~