c++visual-studiowarnings

How can I fix this vs10 inconsistent dll linkage warning?


I have a series of warnings that I'm trying to fix when building gdcm using visual studio 10 (32 bit version):

4>..\..\..\..\gdcm\Utilities\gdcmexpat\lib\xmlparse.c(647): warning C4273: 'XML_ParserCreate' : inconsistent dll linkage
4>          d:\src\gdcm\gdcm\utilities\gdcmexpat\lib\expat.h(206) : see previous definition of 'XML_ParserCreate'

The function call itself looks like:

XML_Parser XMLCALL
XML_ParserCreate(const XML_Char *encodingName)
{
   return XML_ParserCreate_MM(encodingName, NULL, NULL);
}

where

#define XMLCALL __cdecl

and

XMLPARSEAPI(XML_Parser)
XML_ParserCreate(const XML_Char *encoding);

where

#define XMLPARSEAPI(type) XMLIMPORT type XMLCALL

and

#define XMLIMPORT __declspec(dllimport)

If I'm reading that properly, that means that the linkage is consistently __cdecl through XMLCALL-- right? Because, if so, then the warning is superfluous, or am I misinterpreting this?


Solution

  • No, it is complaining about __declspec(dllimport) missing from the function definition but present on the function declaration. You ought to take this seriously, it doesn't make sense to declare the function imported from a DLL but also present in your code. You can't have it both ways.

    This is usually caused by a missing #define. You edited down the macro definitions, I think, but when building the DLL you usually specify a macro in the build command (/D). So that the declaration of the function uses dllexport instead of dllimport. Which ensures that the function gets exported from the DLL. The client code uses the same .h file but is built without that macro defined. It sees the function declared as dllimport.

    Take a closer look at the XMLIMPORT macro definition, __declspec(dllexport) should be close. Another diagnostic is the set of exported functions, visible with Dumpbin.exe /exports. They should be missing if I guessed correctly.