zoukankan      html  css  js  c++  java
  • 在Linux使用mingw32来编写win32程序

    MinGW - Minimalist GNU For Windows

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

    在 Debian 系統中,您可以安裝 DebianPackages:mingw32 、DebianPackages:mingw32-binutils 與 DebianPackages:mingw32-runtime 三個套件軟體。

    DebianPackages:mingw32 包含的就是 g++(c++,cpp)、gcc(cc)、gcov、gccbug 等必備的 win32 跨平台編譯器,您需要這些編譯器產生可在 Microsoft Windows 上使用的 exe、dll 檔案等。DebianPackages:mingw32-binutils 則是 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 <iostream>
    int main(int argc, char* argv[])
    {
    std::cout << "Hello world ";
    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

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

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

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

    user@debian:~$ cat > hello.cpp
    #include <windows.h>
    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 的 putty

    取自"http://wiki.debian.org.tw/index.php/Mingw32"

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

     
  • 相关阅读:
    数据库锁表及阻塞的原因和解决办法
    JS中的this都有什么用?
    vue打包要点
    Vue.js的虚拟dom
    JS继承方式
    JS中的浅拷贝和深拷贝。
    详解计算机原码,反码,补码。
    经常被问到的面试题1
    eslint规则说明
    git常用命令总结
  • 原文地址:https://www.cnblogs.com/lvdongjie/p/3794799.html
Copyright © 2011-2022 走看看