views:

550

answers:

3

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 *'
A: 

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.

Mike McQuaid
Read the question - he needs to build in two different modes, and can only build in one.
David Thornley
Updated to say modes more explicitly. I just assumed that by default the other developers built in Release mode and he did in Debug so I didn't think it needed explicitly spelt out.
Mike McQuaid
+1  A: 

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
da_m_n
That is most likely correct
Eugene
+4  A: 

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.

David Thornley
Some cross platform libraries use unsigned short* instead of wchar_t* to force particular size, as sizeof(wchar_t) can be 2 to 4 bytes depending on compiler and settings. Qt does that I think. Use strings from those libs and wchar_t will cause errors like that when compile flags are incompatible.
Eugene
Thank you. I suppose that means there should be explicitly written conversion functions.
David Thornley
No, that is usually dealt with by using correct compile flags and checks like#if sizeof(wchar_t) != sizeof(unsigned short)# error "bla"#endifOr by using unsigned short* everywhere (hard to do, since other dependencies might use wchar_t)
Eugene