VS2012 C++ 警告 C4005:“__useHeader”:宏重定义
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14363929/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VS2012 C++ warning C4005: '__useHeader': macro redefinition
提问by Jeff B
While migrating an old C++ project from Visual Studio 6 up to Visual Studio 2012, we came across an odd set of warnings from inside the standard Microsoft platform headers:
在将旧的 C++ 项目从 Visual Studio 6 迁移到 Visual Studio 2012 时,我们在标准 Microsoft 平台标头中遇到了一组奇怪的警告:
- warning C4005: '__useHeader' : macro redefinition
- warning C4005: '__on_failure' : macro redefinition
- 警告 C4005:“__useHeader”:宏重新定义
- 警告 C4005:“__on_failure”:宏重新定义
An online search only found a few other people running into this error. In some cases, it was people trying to use VS2012 to compile legacy DirectX code - which I am not doing. In other cases, it was people trying to use VS2012 to target Windows XP (using the new option from Update 1) - which I am doing.
在线搜索仅发现其他一些人遇到此错误。在某些情况下,人们试图使用 VS2012 来编译遗留的 DirectX 代码——我没有这样做。在其他情况下,人们试图使用 VS2012 来定位 Windows XP(使用更新 1 中的新选项)——我正在这样做。
The DirectX question was answered that the warning will always be there to tell you that you're compiling with an out-of-date (pre-Win8) version of DirectX, and you'll just have to live with it.
DirectX 问题得到了回答,警告将始终存在,告诉您您正在使用过期(Win8 之前)版本的 DirectX 进行编译,您只需要忍受它。
The Windows XP question was not answered. Other people simply said that they couldn't reproduce the problem.
没有回答 Windows XP 问题。其他人只是说他们无法重现这个问题。
I reproduced it, and found the cause, which I am writing up here to help anybody else who encounters this.
我复制了它,并找到了原因,我写在这里是为了帮助遇到这种情况的其他人。
回答by Jeff B
Go into the project properties, and find the "Preprocessor Definitions" field.
进入项目属性,找到“预处理器定义”字段。
In addition to the default and added definition constants, you should see a macro:
除了默认和添加的定义常量之外,您还应该看到一个宏:
%(PreprocessorDefinitions)
This macro apparently brings in some additional compiler-provided preprocessor definitions. I am not sure what version of Visual Studio introduced this macro, but it was not therein Visual Studio 6.
这个宏显然引入了一些额外的编译器提供的预处理器定义。我不知道是什么的Visual Studio版本中引入了这个宏,但它是不存在在Visual Studio 6。
In Visual Studio 2012, this macro is requiredto be present in your project's Preprocessor Definitions field. It may also be required in earlier versions of Visual Studio, but I have not tested these.
在 Visual Studio 2012 中,此宏需要出现在项目的预处理器定义字段中。在早期版本的 Visual Studio 中可能也需要它,但我没有测试过这些。
If this macro is missing, you will see the error messages as shown above.
如果缺少此宏,您将看到如上所示的错误消息。
回答by DLRdave
UPDATE:
更新:
See Edmund's answer to this same questionfirst -- give that a try. If it works, great! If not... try the following:
首先请参阅Edmund对同一问题的回答——试一试。如果有效,那就太好了!如果没有...请尝试以下操作:
ORIGINAL:
原来的:
Use the workaround mentioned on the "Workarounds" tab of this web page:
使用此网页的“解决方法”选项卡上提到的解决方法:
Namely, add:
即,添加:
#define _USING_V110_SDK71_ 1
...directly in the .rc file beforeit includes anything that would include the system headers that cause this warning.
...直接在 .rc 文件中,然后它包含任何可能包含导致此警告的系统标头的内容。
回答by softwarebear
Haven't found a solution to this published anywhere online, so here's what worked for me.
还没有找到在线发布的解决方案,所以这对我有用。
I'm building a project with 110_xp tools
我正在用 110_xp 工具构建一个项目
I get these warnings ...
我收到这些警告...
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\sal_supp.h(57): warning C4005: '__useHeader' : macro redefinition
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2872) : see previous definition of '__useHeader'
c:\program files (x86)\microsoft sdks\windows\v7.1a\include\specstrings_supp.h(77): warning C4005: '__on_failure' : macro redefinition
C:\Program Files (x86)\Microsoft Visual Studio 11.0\VC\include\sal.h(2882) : see previous definition of '__on_failure'
Clearly an inconsistency between the VC 11 headers and 7.1a sdk headers.
显然 VC 11 标头和 7.1a sdk 标头之间存在不一致。
In my stdafx.cpp I did this ...
在我的 stdafx.cpp 中,我做了这个......
#define _USING_V110_SDK71_
#include "stdafx.h"
... the build problem has gone away.
...构建问题已经消失。
回答by Edmund
This is a resource compiler warning. The solution is easy. Right click on the .rc file in the solution explorer and choose Properties. Now go to Resources > General > Preprocessor Definitions, and add
这是一个资源编译器警告。解决方法很简单。右键单击解决方案资源管理器中的 .rc 文件并选择属性。现在转到 Resources > General > Preprocessor Definitions,然后添加
%(PreprocessorDefinitions)
回答by Tae-Sung Shin
Adding #define _USING_V110_SDK71_
in Stdafx.cpp or Stdafx.h would not work if your cpp files do not have precompiled headers.
#define _USING_V110_SDK71_
如果您的 cpp 文件没有预编译头,则添加Stdafx.cpp 或 Stdafx.h 将不起作用。
To solve this problem, the following works.
为了解决这个问题,下面的工作。
Right-click project in Solution Explorer* → Properties→ C/C++→ Preprocessor→ Preprocessor definition→ edit→ Add _USING_V110_SDK71_
右键单击解决方案资源管理器中的项目* →属性→ C/C++→预处理器→预处理器定义→编辑→ 添加 _USING_V110_SDK71_
回答by Dorin
For me another solution worked.
对我来说,另一个解决方案有效。
In project Properties→ Configuration properties→ C/C++→ General, I changed the field Addition Include Directoriespath to SDK with this macro:
在项目Properties→ Configuration properties→ C/C++→ General 中,我使用此宏将字段Addition Include Directoriespath更改为 SDK:
$(WindowsSDK_IncludePath)
Before that, this field had the path to my SDK v7.1, and I had the same warnings.
在此之前,这个字段有我的 SDK v7.1 的路径,我也有同样的警告。
回答by Pekka
It is still simpler.
还是比较简单的。
Just check the checkbox "Inherit from parent or project defaults"in Configuration Properties→ C/C++→ Preprocessor / Preprocessor Definitions→ Edit.
只需选中复选框“从父或项目的默认继承”在配置属性→ C / C ++→预处理/预处理器定义→编辑。
回答by 0xC0000022L
For me this happened with Visual Studio 2017 (both fresh and repaired installation). Obviously the Windows 7.1 SDK had been installed before VS2017 and had been integrated into a Visual Studio 2005 installation.
对我来说,这发生在 Visual Studio 2017(全新安装和修复安装)中。很明显,Windows 7.1 SDK 在 VS2017 之前就已经安装好了,并且已经集成到了 Visual Studio 2005 安装中。
In my case the two files:
就我而言,这两个文件:
%LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props
%LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.x64.user.props
%LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.Win32.user.props
%LOCALAPPDATA%\Microsoft\MSBuild\v4.0\Microsoft.Cpp.x64.user.props
contained references to the include directories and libraries of the Windows 7.1 SDK. Removing these references did the job.
包含对 Windows 7.1 SDK 的包含目录和库的引用。删除这些引用完成了工作。
Keep in mind that every single C++ project for Win32 and x64 respectively inherits from these property sheets.
请记住,Win32 和 x64 的每个 C++ 项目都分别继承自这些属性表。
回答by sbel
I know this is old question, but... "sometimes they come back" :)
我知道这是个老问题,但是......“有时他们会回来”:)
Faced same warnings after install VS 2012 Express at fresh OS. After some investigation i decided to compare my current Program Files (x86)\Microsoft Visual Studio 11.0\VC\include
folder with the same folder with VS 2012 Update 4.
Here is comparison result:
在全新的操作系统上安装 VS 2012 Express 后面临同样的警告。经过一番调查,我决定将我当前的Program Files (x86)\Microsoft Visual Studio 11.0\VC\include
文件夹与使用 VS 2012 Update 4 的同一文件夹进行比较。这是比较结果:
So simple copying __useHeader
's checks fixed all warnings.
如此简单的 copying__useHeader
检查修复了所有警告。
回答by Reed Hedges
I had this problem in some projects that originated with VC++ 2003 and have been incrementally upgraded over the years. I found that while the project settings had %(PreprocessorDefinitions)
in Preprocessor Definitions, a few of the .cpp files didn't (The oldest ones). After changing them to "Inherit from parent or project defaults" it got rid of the warnings.
我在一些源自 VC++ 2003 并且多年来一直在逐步升级的项目中遇到了这个问题。我发现虽然项目设置%(PreprocessorDefinitions)
在预处理器定义中,但一些 .cpp 文件没有(最旧的)。将它们更改为“从父级或项目默认值继承”后,它消除了警告。