c++ - MinGW 生成 exe,当在不同系统上运行时生成 "not compatible with the version of Windows"

标签 c++ windows ant mingw

计算机 A 运行 Windows 7 x64。计算机 B 运行 Windows 7 x86。我正在使用 Eclipse、Ant 和 MinGW-w64 在计算机 A 上编译该文件。该文件在计算机 A 上运行良好,但在计算机 B 上出现以下错误:

The version of this file is not compatible with the version of Windows you're running. Check your computer's system information to see whether you need an x86 (32-bit) or x64 (64-bit) version of the program, and then contact the software publisher.

程序是一个文件,main.cpp

#include <windows.h>

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
    MessageBox(NULL, "Goodbye, cruel world!", "Note", MB_OK);
    return 0;
}

ant脚本如下:

<?xml version="1.0" encoding="UTF-8" ?>

<project name="winsock" default="build">
    <taskdef resource="cpptasks.tasks">
    <classpath>
      <pathelement location="E:\_dev\windows\MinGW\msys\home\windoze\projects\Winplay\lib\cpptasks.jar"/>
    </classpath>
  </taskdef>
  <taskdef resource="net/sf/antcontrib/antlib.xml">
    <classpath>
      <pathelement location="E:\_dev\windows\MinGW\msys\home\windoze\projects\Winplay\lib\ant-contrib.jar" />
    </classpath>
  </taskdef>

    <target name="build">
    <mkdir dir="build" />
    <mkdir dir="build/obj" />
    <cc name="g++" objdir="build/obj" debug="${debug}">
      <fileset dir="src" includes="*.cpp" />
      <compiler name="g++">
        <compilerarg value="-std=c++11" />
      </compiler>
    </cc>

    <condition property="debugoption" value="-g -O0" else="-O2">
      <isset property="debug" />
    </condition>   
    <fileset dir="build/obj" id="objects" >
      <include name="*.o" />
    </fileset>
    <pathconvert pathsep=" " property="objectslinker" refid="objects" />  

    <!-- Due to a bug in GppLinker.java in cpptasks.jar, we must exec g++ because GppLinker erroneously uses gcc, which breaks exception handling. -->
    <exec command="g++ -std=c++11 -mwindows ${debugoption} -o build/winplay ${objectslinker}" failonerror="true" />
    </target>

    <target name="clean">
      <delete dir="build" />
    </target>
</project>

为什么 .exe 可以在我的系统上运行,但不能在具有相同 Windows 的系统上运行?我是否需要做一些事情,比如静态链接到 MinGW 使用的窗口定义?

最佳答案

您生成的是 64 位可执行文件,它与任何 32 位版本的 Windows 都不兼容(请注意,反之则不然,如果您生成了 32 位可执行文件, 与 64 位 Windows 兼容...)

要生成 32 位版本的可执行文件,请检查 eclipse 上的“项目选项”。您必须在 ant 文件和项目选项中的某处设置 -march=i686。 Eclipse 的界面上可能有一个复选框/组合框...

关于c++ - MinGW 生成 exe,当在不同系统上运行时生成 "not compatible with the version of Windows",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22888472/

相关文章:

windows - 适用于直接访问的 Windows 的 Git 克隆

java - 如何使用 Ant 删除目录中的所有 .jar 文件?

java - build.xml 中缺少类引用

c++ - 在不明确时在转换运算符之间进行选择

c++ - ofstream* 的 vector 无法打开任何元素

c++ - 如果我们可以使用 vector[1] = someInt,那么 emplace() 的目的是什么?

c++ - 如何在 C++ 中将 UTF-8 编码的字符串写入 Windows 中的文件

windows - 如何在 Windows gyp 上调试 native Node 模块编译

svn - 使用 svnant 缺少类路径上的 svnkit 依赖项

c++ - 用于匹配和计数的字符串和 int 的容器?