我如何修复这个vs10不一致的dll链接警告? [英] How can I fix this vs10 inconsistent dll linkage warning?

查看:556
本文介绍了我如何修复这个vs10不一致的dll链接警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在建立 gdcm using visual studio 10(32 bit version):

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);
}

其中

#define XMLCALL __cdecl

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

其中

#define XMLPARSEAPI(type) XMLIMPORT type XMLCALL

#define XMLIMPORT __declspec(dllimport)

如果我正确地读取,这意味着链接一直__cdecl通过XMLCALL--对吗?因为,如果是这样,那么警告是多余的,或者我是曲解这?

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?

推荐答案

不,它抱怨 __ declspec(dllimport)函数定义,但存在于函数声明上。你应该认真对待,没有意义的声明从DLL导入的函数,但出现在你的代码。您不能同时拥有这两种方式。

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.

这通常是由于缺少#define而导致的。你编辑了宏定义,我想,但在构建DLL时,通常在构建命令(/ D)中指定一个宏。所以函数的声明使用dllexport而不是dllimport。它确保函数从DLL导出。客户端代码使用相同的.h文件,但是在没有定义该宏的情况下构建。它看到的函数声明为dllimport。

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.

仔细看看XMLIMPORT宏定义,__declspec(dllexport)应该是close。另一个诊断是DLL的导出,用Dumpbin.exe / exports可见。如果我正确猜测,它们应该丢失。

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

这篇关于我如何修复这个vs10不一致的dll链接警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆