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

11

29

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:

  • warning C4005: '__useHeader' : macro redefinition
  • warning C4005: '__on_failure' : macro redefinition

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.

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.

The Windows XP question was not answered. Other people simply said that they couldn't reproduce the problem.

I reproduced it, and found the cause, which I am writing up here to help anybody else who encounters this.

Coats answered 16/1, 2013 at 17:12 Comment(0)
C
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.

Coats answered 16/1, 2013 at 17:12 Comment(6)
This macro is added on migration from VS2005 to VS2012 by default and was not helpful in my case. Once, I changed the SDK include directory from v7.1A to $(WindowsSDK_IncludePath) which is version 8.0 all warnings went.Purposive
I have %(PreprocessorDefinitions) and I still get the warnings. The solution with $(WindowsSDK_IncludePath) worked for me.Er
This can also occur when individual source files have preprocessor definitions that override the project definitions.Townspeople
THANK YOU! You should mark your own answer as the answer. It certainly worked for me :DLoewe
Worked for me too: this macro had disappeared from my project settings, putting it back removed the warnings.Mcclees
If you still get this error even after following the above advice, it could be that you also need to add %(PreprocessorDefinitions) in the Resources section of the project property pages.Catfish
A
12

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.

Asinine answered 26/9, 2013 at 17:50 Comment(4)
Wish I saw this a while ago.Enschede
No, don't do this. See Edmund's answer – making sure the individual .rc files properly inherit the project settings.Judson
Thanks for the comment -- I upvoted and linked to Edmund's answer. (Although, I'm trusting that it works without personally verifying. We have since moved up to VS 2013, and the individual .rc files show the inherited defs just fine in VS 2013...)Asinine
This was an interesting hint. In my case, I had this issue when upgrading a VS2010 project to VS2018. Adding _USING_V110_SDK71_=1 to my preprocessor definitions fixed the problem. I am not sure about the proper way to solve this problem though.Corrinacorrine
D
11

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.

Dibrin answered 2/5, 2013 at 11:29 Comment(4)
I got similar warnings as popups when opening the resources in the resource editor, and this tip worked great to remove them.Henriques
Me too, but I had to use ... #if USING_V110_SDK71 == 1 / #define USING_V110_SDK71 1 / #endif // ... to avoid the same warning when compiling stdafx.cpp. It appears they automatically put a /D "USING_V110_SDK71" on the compiler and resource compiler command lines when the Platform Toolset is set to v110_xp. Very strange that this fix affects loading the resources in the resource view of Visual Studio. But don't get me wrong, I'm glad it does. Thanks!Asinine
I take it back..... this fix did not work for me permanently. I still got the error doing it this way. I had to use the workaround mentioned here: connect.microsoft.com/VisualStudio/feedback/details/789965/… in order to get rid of the warning altogether.Asinine
Me too facing the same issue. Any solution found?Collage
H
5

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)
Homesick answered 12/9, 2013 at 13:59 Comment(1)
C4005 error is a compiler error, but some people are getting RC 4005 from the resource compiler, in which case this is their solution. For some reason the individual .rc files lose their inherited settings.Judson
C
5

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.

Crain answered 16/3, 2016 at 11:13 Comment(0)
P
3

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_

Psychoneurosis answered 17/6, 2015 at 17:29 Comment(0)
D
1

It is still simpler.

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

Dumbhead answered 2/3, 2014 at 9:9 Comment(0)
C
1

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.

Caulescent answered 9/8, 2016 at 14:10 Comment(1)
I actually ended up modifying the project files directly and removing all the xml elements for file-specific properties inside each .cpp file's <ClCompile> element.Caulescent
H
1

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.

Hyperpyrexia answered 17/7, 2017 at 18:51 Comment(0)
E
0

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)
Extort answered 12/12, 2016 at 13:23 Comment(0)
P
0

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: enter image description here

And sal.h diffs: enter image description here

So simple copying __useHeader's checks fixed all warnings.

Perdition answered 3/3, 2020 at 22:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.