如何使用 mingw-w64 编译和链接 32 位 Windows 可执行文件 [英] How do I compile and link a 32-bit Windows executable using mingw-w64

查看:54
本文介绍了如何使用 mingw-w64 编译和链接 32 位 Windows 可执行文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的是 Ubuntu 13.04 并使用 apt-get install mingw-w64 安装了 mingw-w64.我可以使用以下命令编译和链接我的程序的工作 64 位版本:

I am using Ubuntu 13.04 and installed mingw-w64 using apt-get install mingw-w64. I can compile and link a working 64-bit version of my program with the following command:

x86_64-w64-mingw32-g++ code.cpp -o app.exe

生成 64 位 app.exe 文件.

Which generates a 64-bit app.exe file.

我使用什么二进制或命令行标志来生成 32 位版本的 app.exe?

What binary or command line flags do I use to generate a 32-bit version of app.exe?

推荐答案

这取决于您当前使用的工具链变体.DWARFSEH 变体(从 GCC 4.8.0 开始)都只是单目标.您可以通过检查其发行版的目录结构自行查看,即它们仅包含具有 64 位或 32 位寻址的库,但不能同时包含两者.另一方面,普通的 SJLJ 发行版确实是双目标的,为了构建 32 位目标,只需提供 -m32 标志.如果这不起作用,那么只需使用 i686-w64-mingw32-g++ 构建.

That depends on which variant of toolchain you're currently using. Both DWARF and SEH variants (which come starting from GCC 4.8.0) are only single-target. You can see it yourself by inspecting the directory structure of their distributions, i.e. they contain only the libraries with either 64- or 32-bit addressing, but not both. On the other hand, plain old SJLJ distributions are indeed dual-target, and in order to build 32-bit target, just supply -m32 flag. If that doesn't work, then just build with i686-w64-mingw32-g++.

顺便说一下,实现每个GCC异常模型的三个相应的动态链接库(DLL)是

By the way, the three corresponding dynamic-link libraries (DLLs) implementing each GCC exception model are

  1. libgcc_s_dw2-1.dll (DWARF);
  2. libgcc_s_seh-1.dll (SEH);
  3. libgcc_s_sjlj-1.dll (SJLJ).
  1. libgcc_s_dw2-1.dll (DWARF);
  2. libgcc_s_seh-1.dll (SEH);
  3. libgcc_s_sjlj-1.dll (SJLJ).

因此,要了解您当前的 MinGW-w64 发行版究竟提供了什么异常模型,您可以

Hence, to find out what exception model does your current MinGW-w64 distribution exactly provide, you can either

  1. 检查 MinGW-w64 安装的目录和文件结构,希望找到这些 DLL 之一(通常在 bin 中);或
  2. 构建一些涉及异常处理的真实或测试 C++ 代码以强制与这些 DLL 之一进行链接,然后查看构建的目标依赖于这些 DLL 中的哪一个(例如,可以通过 Dependency Walker 在 Windows 上);或
  3. 采取蛮力方法并将一些测试代码编译为汇编(而不是机器代码),并查找诸如___gxx_personality_v*(DWARF)、___gxx_personality_seh*(SEH), ___gxx_personality_sj* (SJLJ);请参阅获取当前 GCC 异常模型.
  1. inspect directory and file structure of MinGW-w64 installation in hope to locate one of those DLLs (typically in bin); or
  2. build some real or test C++ code involving exception handling to force linkage with one of those DLLs and then see on which one of those DLLs does the built target depend (for example, can be seen with Dependency Walker on Windows); or
  3. take brute force approach and compile some test code to assembly (instead of machine code) and look for presence of references like ___gxx_personality_v* (DWARF), ___gxx_personality_seh* (SEH), ___gxx_personality_sj* (SJLJ); see Obtaining current GCC exception model.

这篇关于如何使用 mingw-w64 编译和链接 32 位 Windows 可执行文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆