I built a DLL to facilitate reading some data into my .Net app using libraries developed before .Net. So some of the C++ is managed and some is not. After a little bit of fiddling, it all built and tested and (I thought) all was well. Then, when I compiled it in release mode, I got these warnings:
warning C4744: 'static unsigned int * tagVARIANT::* ATL::CVarTypeInfo<unsigned int *>::pmField' has different type in 'c:\tmp\TestForLinkWarning\WithoutCLR.cpp' and 'c:\tmp\TestForLinkWarning\WithCLR.cpp': 'int' and 'struct (4 bytes)'
warning C4744: 'static unsigned char tagVARIANT::* ATL::CVarTypeInfo<unsigned char>::pmField' has different type in 'c:\tmp\TestForLinkWarning\WithoutCLR.cpp' and 'c:\tmp\TestForLinkWarning\WithCLR.cpp': 'int' and 'struct (4 bytes)'
... (and a great deal more like them) ..
These objects all come from atlcomcli.h, included via a common header.
I figured that if I diffed the preprocessor output for the two files, I'd stumble on some #pragma or another that caused the whole thing. But I had no luck with that.
After a little more investigation, I found that I could reproduce the problem simply by creating a header file: struct VARIANT
{
char cVal;
};
class CVarTypeInfo
{
static char VARIANT::* const pmField;
};
__declspec( selectany ) char VARIANT::* const CVarTypeInfo::pmField = &VARIANT::cVal;
This header file, when included from files with CLR turned on and off, will reproduce the problem. But again, only in release mode.
So I started looking at Compiler-switches and found that if I removed /GL from the C++ compiler's command line ("Whole Program Optimization") and also removed the corresponding /LTCG switch ("Link-Time Code Generation") from the linker, I got a clean build.
Is that a correct remedy for the problem Is there a better way Are there consequences to doing this that I should be aware of
Visual C++15
|