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

查看:2222
本文介绍了如何使用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?

推荐答案

这取决于您当前正在使用哪种工具链. DWARF SEH 变体(从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- and 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(例如,可以使用获取当前的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天全站免登陆