简体   繁体   English

C ++在Unicode Release MinDependency中编译错误,但在Debug中没有

[英]C++ compile errors in Unicode Release MinDependency but not in Debug

Let me start out by saying I'm in charge of the creating and managing the builds and installs and I'm not a C++ developer so most of the errors below are incomprehensible to me. 首先,我要说我负责创建和管理构建和安装,而且我不是C ++开发人员,所以下面的大多数错误对我来说都是不可理解的。

That being said a developer (not around right now) checked in some code that compiles fine in Debug|Win32 (using VS08) but I need to get it to compile in Unicode Release MinDependency|Win32. 这就是说开发人员(现在不是)现在检查了一些在Debug | Win32(使用VS08)中编译良好的代码,但是我需要在Unicode Release MinDependency | Win32中编译它。

There are 88 error but all seem to come down to 'convert' issues, and all are just multiple occurrences of the ones listed below. 有88个错误,但似乎都归结为“转换”问题,所有这些只是下面列出的问题的多次出现。

  • Are the compile errors something fundamental with how it was coded (C++, ATL)? 编译错误是否与编码错误有关(C ++,ATL)?

  • Is there some compile option switch or VS setting I can change to get this to compile as MinDep? 是否有一些编译选项开关或VS设置我可以更改以使其编译为MinDep?

  • Is there a brief explanation of what is causing this so I understand the issues at hand? 是否有一个简短的解释是什么导致了这一点,所以我理解手头的问题?

Errors: 错误:

cannot convert from 'unsigned short *' to 'ATL::CComBSTR'
cannot convert from 'wchar_t *' to 'unsigned short *'
cannot convert parameter 1 from 'unsigned short *' to 'wchar_t *'
cannot convert parameter 1 from 'LPWSTR' to 'const unsigned short *'
cannot convert parameter 2 from 'BSTR' to 'const unsigned short *'
cannot convert parameter 2 from 'LPWSTR' to 'const unsigned short *'
none of the 2 overloads could convert all the argument types
cannot convert parameter 1 from 'unsigned short *' to 'const OLECHAR *'
cannot convert parameter 1 from 'unsigned short [4096]' to 'wchar_t *'

The problem is that the code was badly written. 问题是代码编写得很糟糕。 The developer made assumptions about characters and integer types that don't hold when you compile in Unicode. 开发人员假设在使用Unicode编译时不能保留的字符和整数类型。 The problem is not with Visual C++, ATL, or Visual Studio. 问题不在于Visual C ++,ATL或Visual Studio。

There is, obviously, a compiler switch you can use to make it compile, since that's presumably the main difference between the Debug and the Unicode Release Mindependency versions. 很明显,您可以使用编译器开关进行编译,因为这可能是Debug和Unicode Release Mindependency版本之间的主要区别。 However, you don't want to switch it, because it would mean you're no longer doing the actual Unicode Release Mindependency build. 但是,您不希望切换它,因为这意味着您不再执行实际的Unicode Release Mindependency构建。

You'll notice that every one of your conversion messages is between unsigned short * (a pointer to a particular integer type) and some representation of a string. 您会注意到,每个转换消息都在unsigned short * (指向特定整数类型的指针)和字符串的某种表示之间。 In properly written C++, you don't convert between integral and character types all over the place. 在正确编写的C ++中,您不能在整个地方之间转换整数和字符类型。 It may be necessary to do so, for example when dealing with legacy code, but it is a source of potential problems and does need to be watched carefully. 可能有必要这样做,例如在处理遗留代码时,但它是潜在问题的根源,需要仔细观察。

You need this code to be rewritten. 您需要重写此代码。 You said the developer was not around (fired for doing stuff like this, maybe?), so you'll have to get another developer to fix it. 你说开发人员不在身边(因为做这样的事情而被解雇了,也许?),所以你必须让另一个开发者来解决它。

There are a couple of places in Visual Studio IDE (2008 assumed here) where you can check to have the same settings in both debug and release builds: Visual Studio IDE中有几个地方(此处假设为2008),您可以在其中检查调试和发布版本中是否具有相同的设置:

Project Properties -> General -> Character Set (set to Use Unicode Character Set ) 项目属性 - >常规 - >字符集(设置为使用Unicode字符集)

Project Properties -> C/C++ -> Language -> Treat wchar_t as Built-in Type ( usually set to Yes ) 项目属性 - > C / C ++ - >语言 - >将wchar_t视为内置类型(通常设置为是)

Project Properties -> C/C++ -> Command Line - you should see defined both UNICODE and _UNICODE 项目属性 - > C / C ++ - >命令行 - 您应该看到定义了UNICODE和_UNICODE

If these settings are the same in both builds - it might get a little worse as it could happen because of conditional compilation and in there it depends on what specific libraries he's working with or his code. 如果这两个版本中的设置相同 - 由于条件编译可能会发生更糟糕的情况,并且在那里它依赖于他正在使用的特定库或他的代码。

You can read here http://msdn.microsoft.com/en-us/library/xt153e2k(VS.71).aspx about what MinDependency means. 你可以在这里阅读http://msdn.microsoft.com/en-us/library/xt153e2k(VS.71).aspx关于MinDependency的含义。 It's actually a define for ATL on how to link against crt. 它实际上是ATL关于如何链接crt的定义。

Note that wchar_t is defined as unsigned short - so it's just missing the define there - not an actual bug of conversion as said above. 请注意,wchar_t被定义为unsigned short - 所以它只是缺少那里的定义 - 而不是如上所述的实际转换错误。 I don't have a VC 6 to test it but under VC9 it's something like this : 我没有VC 6来测试它,但在VC9下它是这样的:

#ifndef _WCHAR_T_DEFINED
typedef unsigned short wchar_t;
#define _WCHAR_T_DEFINED
#endif

The errors all look string related. 错误都与字符串相关。 Someone has probably enabled/disabled unicode and/or wide strings in Debug mode in Release mode. 有人可能在发布模式下的调试模式下启用/禁用了unicode和/或宽字符串。 Try flipping these settings in the Visual Studio's the Release mode's settings and see if it compiles. 尝试在Visual Studio的“发布”模式的设置中翻转这些设置,看看它是否可以编译。 Alternatively, check all the settings match between the Release and Debug modes. 或者,检查Release和Debug模式之间的所有设置匹配。

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

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