VS2012 C++ warning C4005: '__useHeader': macro redefinition

青春壹個敷衍的年華 提交于 2019-11-29 01:04:21

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 there in Visual Studio 6.

In Visual Studio 2012, this macro is required to 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.

If this macro is missing, you will see the error messages as shown above.

DLRdave

UPDATE:

See Edmund's answer to this same question first -- give that a try. If it works, great! If not... try the following:

ORIGINAL:

Use the workaround mentioned on the "Workarounds" tab of this web page:

http://connect.microsoft.com/VisualStudio/feedback/details/789965/resource-editor-warning-rc4005-on-toolset-visual-studio-2012-windows-xp-v110-xp

Namely, add:

#define _USING_V110_SDK71_ 1

...directly in the .rc file before it includes anything that would include the system headers that cause this warning.

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

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.

In my stdafx.cpp I did this ...

#define _USING_V110_SDK71_

#include "stdafx.h"

... the build problem has gone away.

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

%(PreprocessorDefinitions)
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.

To solve this problem, the following works.

Right-click project in Solution Explorer* → PropertiesC/C++PreprocessorPreprocessor definitionedit → Add _USING_V110_SDK71_

Dorin

For me another solution worked.

In project PropertiesConfiguration propertiesC/C++General, I changed the field Addition Include Directories path to SDK with this macro:

$(WindowsSDK_IncludePath)

Before that, this field had the path to my SDK v7.1, and I had the same warnings.

Pekka

It is still simpler.

Just check the checkbox "Inherit from parent or project defaults" in Configuration PropertiesC/C++Preprocessor / Preprocessor DefinitionsEdit.

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.

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

contained references to the include directories and libraries of the Windows 7.1 SDK. Removing these references did the job.

Keep in mind that every single C++ project for Win32 and x64 respectively inherits from these property sheets.

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.

Although this answer is for VS10, it's of interest as might provide some clues as to what's going on viz the VC++ directories macros: The warning appeared when these statements were added in the header file of a project, MyApp:

#ifndef NTDDI_WINXPSP3
#define NTDDI_WINXPSP3 0x05010300
#endif 
#ifndef NTDDI_VISTA
#define NTDDI_VISTA 0x06000000
#endif 
#ifndef NTDDI_VISTASP1
#define NTDDI_VISTASP1 0x06000100
#endif 
#ifndef NTDDI_WS08
#define NTDDI_WS08 0x06000100
#endif 

Warnings like the following popped up for all but the XPSP3 def.:

Warning RC4005: 'NTDDI_VISTASP1' : redefinition C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\include\sdkddkver.h.., MyApp

MyApp was a WinDebug 32 build, noting Windows7.1SDK appeared in the X64 section of the proj file:

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<PlatformToolset>Windows7.1SDK</PlatformToolset>

The inherited value for Preprocessor Definitions was _VC80_UPGRADE=0x0600. Having used the SDK toolset prior to reverting to V100, the SDK libraries were found as inherited_from in Include directories and Library Directories in the VC++ Directories section, as noted here.
Looks like the warning is generated as a result of a combination of upgrading, migration, or toolset changes.

Edit: An unrelated issue in VS2017 (MBCS) is opting to use

LoadCursorW(nullptr, IDC_ARROW)

instead of the default LoadCursorA(...) in a WNDCLASSEXW structure. A possible solution is to redefine like so:

 #define IDC_ARROW           MAKEINTRESOURCEW(32512)

Here the warning can be suppressed by using the #undef procedure prior to the #define:

#ifdef IDC_ARROW
#undef IDC_ARROW
#endif
#define IDC_ARROW           MAKEINTRESOURCEW(32512)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!