简体   繁体   English

Visual Studio 2008 Express C ++ 32位在Windows 7 64位上构建

[英]Visual Studio 2008 Express C++ 32 bit build on Windows 7 64 bit

I am using Visual Studio 2008 Express. 我正在使用Visual Studio 2008 Express。 I have a solution which used to work fine on Vista 32 bit. 我有一个曾经在Vista 32位上正常工作的解决方案。 I recently switched over to Windows 7, and part of it stopped working. 我最近切换到Windows 7,部分停止了工作。 This is my setup: - Unmanaged C++ static library, "the library" - Managed C++ DLL that wraps functionality of "the library" for use in C#, "the DLL" - Managed C++ console application that references "the DLL" - C# application that references "the DLL" 这是我的设置:-非托管C ++静态库,“库”-封装了“库”功能以供C#使用的托管C ++ DLL,“ DLL”-引用“ DLL”的托管C ++控制台应用程序-C#应用程序引用“ DLL”

I am getting an exception thrown by the DLL when running the C# application, and I usually debug problems like that through the managed C++ console app, since I can then step into the unmanaged library code. 运行C#应用程序时,DLL引发了异常,我通常通过托管C ++控制台应用程序调试类似的问题,因为这样便可以进入非托管库代码。

The problem is that I now get a popup dialog with some weird symbols and the path to "C:\\Windows\\Microsoft.NET\\Framework\\v2.0.50727\\dw20.exe" , and then my app catches an exception "System.BadImageFormatException: is not a valid Win32 application" thrown when I try to run the managed C++ console app. 问题是我现在得到一个弹出对话框,其中包含一些奇怪的符号和“ C:\\ Windows \\ Microsoft.NET \\ Framework \\ v2.0.50727 \\ dw20.exe”的路径,然后我的应用程序捕获到异常“ System.BadImageFormatException” :当我尝试运行托管C ++控制台应用程序时,抛出“:不是有效的Win32应用程序” I have spent a lot of time researching this issue, and anything that even remotely resembles useful advice refers to building X86 projects in C#, but nothing about C++. 我已经花了很多时间研究这个问题,并且甚至在任何方面都与有用的建议都不太相像的东西都是在C#中构建X86项目,但与C ++无关。 I tried adding /MACHINE:X86 to the Librarian options of the library, but that doesn't seem to work. 我尝试将/ MACHINE:X86添加到库的Librarian选项中,但这似乎不起作用。

I guess in short my question is, how do I get to make sure my unmanaged C++ static library builds so that it can run on 32 bit systems? 简而言之,我想我的问题是,如何确保建立不受管理的C ++静态库,以便它可以在32位系统上运行?

The dw20.exe program is "Doctor Watson", the program that reports unhandled runtime exceptions and crashes. dw20.exe程序是“ Doctor Watson”,该程序报告未处理的运行时异常和崩溃。 Not the source of the problem, merely the messenger. 不是问题的根源,而只是使者。 Although unstated in the question, I have to assume your Windows 7 version is 64-bit, the common source of System.BadImageFormatException. 尽管该问题未作说明,但我必须假定您的Windows 7版本是64位,这是System.BadImageFormatException的常见来源。

The exception is caused by a 64-bit process trying to load a DLL that was built for 32-bit. 该异常是由64位进程尝试加载为32位生成的DLL引起的。 Or the other way around, a 32-bit process cannot load a 64-bit DLL. 或相反,一个32位进程无法加载64位DLL。 The bitness of the process is determined by the EXE, a C++/CLI app in your case. 进程的位数由EXE(在您使用的情况下为C ++ / CLI应用)确定。 It doesn't have the option to change it with a simple project setting, like C# projects do. 它没有像C#项目那样通过简单的项目设置来更改它的选项。 You do it by adding a platform, "x64" uses the 64-bit compiler and generates a 64-bit executable. 您可以通过添加平台来实现,“ x64”使用64位编译器并生成64位可执行文件。 I'm pretty sure that is not available in the C++ Express edition though, you don't have the 64-bit compilers so must always generate a 32-bit executable. 我非常确定C ++ Express版本中没有该功能,因为您没有64位编译器,因此必须始终生成32位可执行文件。

Which leaves very little room to explain the exception. 剩下很少的空间来解释异常。 It could only go wrong if you changed the Platform target setting in your C# class library project. 仅当您在C#类库项目中更改了平台目标设置时,它才会出错。 From x86 or AnyCPU to x64. 从x86或AnyCPU到x64。 Change it back to AnyCPU. 将其更改回AnyCPU。 Project + Properties, Build tab. 项目+属性,生成选项卡。 If you have done anything to hack around the limitations of the Express edition, like adding 64-bit compilers from an SDK release then that would be a major red flag for the source of the problem as well. 如果您为绕开Express版本的限制做了任何事情,例如从SDK版本中添加64位编译器,那么对于问题的根源,这也是一个主要的危险信号。

Change the built from Any CPU to 32 or 86, and you should have no problem. 将内置的任何CPU更改为32或86,您应该没有问题。 you probably are using in the c++ code a windows 32 dll that's why it doesn't work on other platforms. 您可能在C ++代码中使用了Windows 32 dll,这就是为什么它在其他平台上不起作用的原因。 Any CPU-> configuration Manager then change to 32 or 86 然后将任何CPU-> Configuration Manager更改为32或86

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

相关问题 C ++ Visual Studio 2008,将项目从64位迁移到32位 - C++ Visual Studio 2008, moving a project from 64-bit to 32-bit Microsoft Visual Studio 2008 C ++错误LNK2001,Windows Vista 64位 - Microsoft Visual Studio 2008 C++ error LNK2001, Windows Vista 64 bit 使用Visual Studio C ++ 2010 Express在Windows x 86(32位)上安装适用于Python 3.4的lxml - Installing lxml for Python 3.4 on Windows x 86 (32 bit) with Visual Studio C++ 2010 Express Visual Studio - C++ - 以 32 位或 64 位形式构建和运行应用程序 - 从适当的 ProgramFiles 目录加载 DLL - Visual Studio - C++ - build and run app as 32bit or 64bit - load DLL from appropripate ProgramFiles dir 使用Visual Studio 2010的32位C ++到64位C ++ - 32-bit C++ to 64-bit C++ using Visual Studio 2010 将我的Visual Studio C ++项目从64位迁移到32位系统 - Moving my Visual Studio C++ project to 32 bit system from 64 bit C ++:从32位到64位的迁移 - C++: 32 bit to 64 bit migration Visual Studio 2008 64 位上的 C++ Boost 库,编译器无法打开 .obj 文件 - C++ Boost libraries on Visual Studio 2008 64-bit, compiler cannot open .obj file Visual Studio 2008 sp1 vc ++项目可以在32位模式下工作,但不能在64位模式下工作 - Visual Studio 2008 sp1 vc++ project works in 32 bit mode, but not 64 bit 如何使用visual c ++ 2008编译64位 - How can I compile 64 bit with visual c++ 2008
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM