宏重新定义警告 [英] Macro redefinition warnings

查看:296
本文介绍了宏重新定义警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将Windows驱动程序项目从VS 2005迁移到VS 2012.在VS 2012上会生成许多宏重新定义警告,例如-

I am migrating a windows driver project from VS 2005 to VS 2012. Many macro redefinition warnings are generated on VS 2012 like -

....

1>C:\WINDDK\7600.16385.1\inc\api\sal.h(707): warning C4005: '__format_string' : 
                                                                macro redefinition
1>          c:\program files (x86)\microsoft visual studio 11.0\vc\include\sal.h(2860) : 
                                       see previous definition of '__format_string'

.....

使用VS 2005附带的sal.h可以正常编译,因为它没有宏__format_string和其他宏.但是,VS 2012附带的sal.h具有这些宏.因此,在VS 2012中,驱动程序的sal.h与标准的sal.h之间存在冲突.

It was compiling fine with sal.h shipped with VS 2005 because it doesn't have the macro __format_string and others. However, the sal.h shipped with VS 2012 has these macros. Thus having conflicts between the driver's sal.h and the standard sal.h with VS 2012.

#define __format_string                            // With DDK
#define __format_string    _Printf_format_string_  // On VS 2012

我不能忽略标准标头,因为它们是在构建过程中使用的.

I cannot ignore the standard headers because they are used in the build process.

....
1> Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\string.h
1> Note: including file:  C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\crtdefs.h
....

sal.h中没有关于这些宏的#if指令,因此我可以在VS 2012中使用#undef.是否可以解决此问题?

There is no #if directive around these macros in sal.h so that I can #undef it in VS 2012. Is there any work around for this issue ?

谢谢.

推荐答案

您不应在驱动程序代码中包含VS标准标头,它们不适合内核使用.仅使用WDK标头.

You shouldn't include the VS standard headers in driver code, they aren't for kernel usage. Use WDK headers only.

这篇关于宏重新定义警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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