简体   繁体   中英

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.

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.

There are 88 error but all seem to come down to 'convert' issues, and all are just multiple occurrences of the ones listed below.

  • Are the compile errors something fundamental with how it was coded (C++, ATL)?

  • Is there some compile option switch or VS setting I can change to get this to compile as 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. The problem is not with Visual C++, ATL, or 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. However, you don't want to switch it, because it would mean you're no longer doing the actual Unicode Release Mindependency build.

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. In properly written C++, you don't convert between integral and character types all over the place. 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:

Project Properties -> General -> Character Set (set to Use Unicode Character Set )

Project Properties -> C/C++ -> Language -> Treat wchar_t as Built-in Type ( usually set to Yes )

Project Properties -> C/C++ -> Command Line - you should see defined both UNICODE and _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. It's actually a define for ATL on how to link against 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. I don't have a VC 6 to test it but under VC9 it's something like this :

#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. Try flipping these settings in the Visual Studio's the Release mode's settings and see if it compiles. Alternatively, check all the settings match between the Release and Debug modes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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