C++ Visual Studio 2012 64 位系统上的 32 位编译

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15706024/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 19:40:37  来源:igfitidea点击:

Visual Studio 2012 32bit compilation on 64bit system

c++visual-c++dllvisual-studio-201232-bit

提问by joker.neophyte

I have recently wanted to build a dll plugin for a program. Problem is, the program is 32bit, but by default my Visual Studio 2012's C++ compiler creates 64bit binaries, and I don't know how to change it - I've found the Configuration Manager and tried to create a new platform but there's only x64 as an option.

我最近想为程序构建一个 dll 插件。问题是,该程序是 32 位的,但默认情况下,我的 Visual Studio 2012 的 C++ 编译器创建了 64 位二进制文​​件,我不知道如何更改它 - 我找到了配置管理器并尝试创建一个新平台,但只有 x64作为一种选择。

Am I trying to set the target architecture in the wrong place or what? Is there an update or something I can download so that I can create my dll? Is there a compiler switch that I can set somewhere?

我是想在错误的地方设置目标架构还是什么?是否有更新或我可以下载的东西,以便我可以创建我的 dll?是否有我可以在某处设置的编译器开关?

Hope this screen helps:

希望这个屏幕有帮助:

enter image description here

在此处输入图片说明

回答by Mani Ghasemnia Hamedani

To build for 32 bit architecture, you have to open project properties window, and then Linker options.

要构建 32 位架构,您必须打开项目属性窗口,然后打开链接器选项。

Set the value of Target Machine option to MachineX86.

将 Target Machine 选项的值设置为 MachineX86。

回答by Ajay

  • Check the Build Configuration (Build -> Configuration Manager), and ensure that your DLL project for 32-bit is selected.
  • Check the linker settings, and ensure correct path is given.
  • After build, check that .DLL is produced at correct path, and is 32-bit (should be!).
  • 检查构建配置(构建 -> 配置管理器),并确保选择了 32 位的 DLL 项目。
  • 检查链接器设置,并确保给出正确的路径。
  • 构建后,检查 .DLL 是否在正确的路径上生成,并且是 32 位(应该是!)。

You can use Dependency Walker to check if DLL is 32-bit or 64-bit. You also didn't mention if /clroption is used with this DLL or not. With /CLR, managed binary is produced. Though this option wouldn't alter bit-nessof the binary, you can just check if this is the case.

您可以使用 Dependency Walker 检查 DLL 是 32 位还是 64 位。您也没有提到/clr选项是否与此 DLL 一起使用。使用/CLR,生成托管二进制文件。尽管此选项不会改变二进制文件的位数,但您可以检查是否是这种情况。