在 64 位计算机上使用 Visual Studio 编译 32 位应用程序
我正在尝试在全新安装 Windows 7 的 64 位计算机上使用 Visual Studio 2010 编译用 C 编写的简单 32 位 Hello World 应用程序。安装 Visual Studio 后,我还安装了“Windows SDK for Windows 7 and .NET Framework 4”。 我构建的应用程序选择“Win32”作为平台。它可以在 Windows 7 上运行,但如果我在 Windows XP Professional 的 32 位计算机上运行该应用程序(也是全新安装,没有软件和服务包),它似乎无法正常工作并出现此错误:
"This application has failed to start because msvcr100.dll was not found"
如果它有用,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(图)
如何解决?谢谢!
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. I also installed the "Windows SDK for Windows 7 and .NET Framework 4" after installing Visual Studio.
I built the application selecting "Win32" as platform. 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:
"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):
"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)
How can I solve it? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
运行它的机器需要运行时库。请参阅此 MSDN 信息。
The machine on which it is run needs the runtime libraries. See this MSDN information.
不要相信 Dependency Walker 对此...它清楚地表明您的 exe 是 32 位的。您的问题出在 VC 可再发行组件上,即 CRT dll - 在 VS 安装中查找 vcredist_x86.exe。您应该在运行应用程序之前运行它。
另一种选择是静态链接 CRT。请参阅/MT 选项。会使你的 exe 更大,但保存 vcredist 的东西。
Don't trust Dependency Walker on this... It clearly shows your exe is 32 bit. Your problem is with the VC redistributables, which are the CRT dlls - look for vcredist_x86.exe in your VS installation. You should run it before you run your app.
Another option is to statically link the CRT. See the /MT option. Will make your exe larger, but save the vcredist stuff.
这里的问题是 Windows XP 机器上缺少编译程序使用的 C 运行时。 Visual Studio 2010 默认使用 10.0 (msvcr100.dll) 运行时,默认情况下 XP 上不可用。您需要在计算机上手动部署 C 运行时才能运行程序。
您可能需要阅读以下 MSDN 文章,其中讨论了部署使用 Visual Studio 2010 构建的 C 应用程序的相关问题
工作中可能存在其他 32 / 64 个问题,但这似乎成为首要问题
The problem here is the C runtime used by the compiled program is missing on the Windows XP machine. Visual Studio 2010 will by default us the 10.0 (msvcr100.dll) runtime which is not available on XP by default. You need to manually deploy the C runtime on your machine in order for your program to run.
You may want to read the following MSDN article which discusses the issues around deploying C applications built with Visual Studio 2010
There may be additional 32 / 64 issues at work but this appears to be the primary problem
关于运行时库的答案是正确的。另一种可能的解决方案是链接到静态运行时库而不是 DLL 版本。通过这种方式,您可以构建一个可执行文件,并将其拖放到任何计算机上,而无需额外的部署麻烦。
这是一种权衡,但是,在不了解更多有关您的情况的情况下,可能值得考虑。
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. 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.