简体   繁体   English

在 64 位机器上使用 Visual Studio 编译 32 位应用程序

[英]Compiling 32-bit application using Visual Studio on a 64-bit machine

I'm trying to compile a simple 32-bit Hello World application written in C using Visual Studio 2010 on a 64-bit machine on a Windows 7 fresh install.我正在尝试在 Windows 7 全新安装的 64 位机器上使用 Visual Studio 2010 编译用 C 编写的简单 32 位 Hello World 应用程序。 I also installed the "Windows SDK for Windows 7 and .NET Framework 4" after installing Visual Studio.在安装 Visual Studio 后,我还为 Windows 7 和 .NET Framework 4 安装了“Windows SDK”。 I built the application selecting "Win32" as platform.我构建了选择“Win32”作为平台的应用程序。 It works on Windows 7 but if I run the application on my 32-bit machine with Windows XP Professional (fresh install also this, without softwares and Service Packs) it seems not working getting this error:它适用于 Windows 7,但如果我使用 Windows XP Professional 在我的 32 位机器上运行该应用程序(全新安装,没有软件和服务包),似乎无法正常工作,出现此错误:

"This application has failed to start because msvcr100.dll was not found"

If it can be useful Dependency Walker detects 2 errors (see the linked picture for details):如果它有用 Dependency Walker 检测到 2 个错误(有关详细信息,请参阅链接图片):

"Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module."
"Error: Modules with different CPU types were found."

http://img820.imageshack.us/img820/4725/errordp.png (PIcture) http://img820.imageshack.us/img820/4725/errordp.png (图片)

How can I solve it?我该如何解决? Thanks!谢谢!

The machine on which it is run needs the runtime libraries.运行它的机器需要运行时库。 See this MSDN information .请参阅此MSDN 信息

The problem here is the C runtime used by the compiled program is missing on the Windows XP machine.这里的问题是Windows XP机器上缺少编译程序使用的C运行时。 Visual Studio 2010 will by default us the 10.0 (msvcr100.dll) runtime which is not available on XP by default.默认情况下,Visual Studio 2010 将使用 10.0 (msvcr100.dll) 运行时,默认情况下在 XP 上不可用。 You need to manually deploy the C runtime on your machine in order for your program to run.您需要在您的机器上手动部署 C 运行时才能运行您的程序。

You may want to read the following MSDN article which discusses the issues around deploying C applications built with Visual Studio 2010您可能需要阅读以下 MSDN 文章,该文章讨论了有关部署使用 Visual Studio 2010 构建的 C 应用程序的问题

There may be additional 32 / 64 issues at work but this appears to be the primary problem工作中可能还有其他 32 / 64 问题,但这似乎是主要问题

Don't trust Dependency Walker on this... It clearly shows your exe is 32 bit.不要相信 Dependency Walker... 它清楚地表明您的 exe 是 32 位的。 Your problem is with the VC redistributables, which are the CRT dlls - look for vcredist_x86.exe in your VS installation.您的问题在于 VC 可再发行组件,即 CRT dll - 在您的 VS 安装中查找 vcredist_x86.exe。 You should run it before you run your app.您应该在运行应用程序之前运行它。

Another option is to statically link the CRT.另一种选择是静态链接 CRT。 See the /MT option .请参阅/MT 选项 Will make your exe larger, but save the vcredist stuff.会使你的 exe 更大,但保存 vcredist 的东西。

The answers about the runtime library are correct.关于运行时库的答案是正确的。 Another possible solution is to link to the static runtime libraries rather than to the DLL versions.另一种可能的解决方案是链接到 static 运行时库而不是 DLL 版本。 This way you can build an executable that you can drop onto any machine without extra deployment hassles.通过这种方式,您可以构建一个可执行文件,您可以将其放到任何机器上,而无需额外的部署麻烦。

It's a trade-off, but, without knowing more about your situation, it might be worth considering.这是一个权衡,但是,在不了解您的情况的情况下,可能值得考虑。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM