如何摆脱“内联函数已使用但从未定义” g++ 中的警告
我正在使用 mingw-w64。我包含 strsafe.h
并收到以下警告:
warning: inline function 'HRESULT StringCchPrintfA(STRSAFE_LPSTR, size_t, STRS
AFE_LPCSTR, ...)' used but never defined [enabled by default]
我使用的唯一标志是 -Wall -DDEBUG -g
。我知道你必须在同一个标头中定义内联函数,我查看了 strsafe.h
,我清楚地可以看到标头中的 StringCchPrintfA
,所以我不这样做知道为什么它给我这个错误。另外,如果您愿意,这里还有指向 strsafe.h 的链接自己查看标题。
编辑:
我在网上找到了以下片段(如果有人可以提供更多信息,请告诉我,评论中想说什么?):
// Work around lack of strsafe library in mingw-w64, do let their
// strsafe.h provide inlines of StringCchVPrintfA etc, avoid linking
// errors in a debug build.
#ifdef __CRT__NO_INLINE
#undef __CRT__NO_INLINE
#define DID_UNDEFINE__CRT__NO_INLINE
#endif
extern "C" {
#endif
#include <strsafe.h>
#ifdef __MINGW32__
}
#ifdef DID_UNDEFINE__CRT__NO_INLINE
#define __CRT__NO_INLINE
#endif
#endif
I'm using mingw-w64. I'm including strsafe.h
and getting the following warning:
warning: inline function 'HRESULT StringCchPrintfA(STRSAFE_LPSTR, size_t, STRS
AFE_LPCSTR, ...)' used but never defined [enabled by default]
The only flags flags I used are -Wall -DDEBUG -g
. I know that you have to define inline functions in the same header and I looked at strsafe.h
and I clearly can see that StringCchPrintfA
in the header, so I don't know why its giving me this error. Also, here is a link to strsafe.h if you want to look at the header yourself.
Edit:
I found the following snippet online (if anybody can provide more information please let me know, what are the trying to say in the comment?):
// Work around lack of strsafe library in mingw-w64, do let their
// strsafe.h provide inlines of StringCchVPrintfA etc, avoid linking
// errors in a debug build.
#ifdef __CRT__NO_INLINE
#undef __CRT__NO_INLINE
#define DID_UNDEFINE__CRT__NO_INLINE
#endif
extern "C" {
#endif
#include <strsafe.h>
#ifdef __MINGW32__
}
#ifdef DID_UNDEFINE__CRT__NO_INLINE
#define __CRT__NO_INLINE
#endif
#endif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该评论表明应该有一个 strsafe 库,但它不存在。
__CRT__NO_INLINE
定义必须暗示某个地方有一个已编译的库来提供函数,而不是使用标头中的内联函数。因此,在该库不存在的情况下(但似乎认为应该存在),允许使用内联函数。
但是,这是为了修复链接错误。编译代码时是否出现链接错误?或者你只是收到警告?如果您只收到警告,则意味着您实际上拥有 strsafe 库。完全有可能的是,没有办法消除该消息并仍然使用该函数的编译版本。
The comment is indicating that there is supposed to be a strsafe library but it's not there. The
__CRT__NO_INLINE
definition must imply that there is a compiled library somewhere to provide the functions instead of using the inline'd ones from the header.So, in the case where that library is not present (but it seems to think it should be), allow the inline functions to be used.
But, this is to fix linking errors. Do you get linking errors when you compile your code? Or do you just get the warning? If you only get the warning, it means you do in fact have the strsafe library. It's entirely plausible that there is no way to eliminate the message and still use the compiled version of the function.