MSVC fails with compiler errors without compiling any sources

。_饼干妹妹 提交于 2019-12-05 21:21:46

(Reposting from comment so question can be marked answered.)

You shouldn't be compiling normal code with the resource compiler.

While the marked answer is already correct here some background: The MSVC Resource Compiler truncates macro names at char 31. Similar problems occur also with newer system headers like those from VC10 or later which have macro names defined with more than 31 chars. See also M$'s reply who call this simply 'by design' instead of fixing their RC.EXE:

http://connect.microsoft.com/VisualStudio/feedback/details/532929/rc4011-warnings-from-vc10-rc

Affected system headers with macro names greater than 31 chars are since VC10 string.h, tchar.h, wchar.h, yvals.h and probably some more ... see also:

http://social.msdn.microsoft.com/Forums/vstudio/en-US/ea289832-c48c-475b-a922-bf94d2ee54e4/vs2012-update-1-fatal-error-rc10056-in-c-project-when-v110xp-platform-is-chosen

When attempting to use Visual Studio 2013 to compile for Windows XP and POS Ready 2009 as a target, I ran into a similar problem. The application compiled fine with the standard Visual Studio 2013 (v120) setting in the Platform Toolset Configuration Properties however when changed to Visual Studio 2013 - Windows XP (v120_xp) to target Windows XP, I received a compilation error of:

>C:\Program Files (x86)\Microsoft SDKs\Windows\v7.1A\include\winsock2.h(2752): fatal error RC10056:

Jumping to the location in the WinSock2.h include file showed a function prototype which used the __out_bcount_part_opt() macro.

After seeing this posting I realized that the error was a resource compiler error. Looking further what I discovered was that a header file, piflocal.h, that was included in both the source code and the resource file contained an include of the WinSock2.h header file.

In other words the application source code had a header file, piflocal.h, which contained defines needed by the header file resource.h used by the resource file pif.rc as well as the C source files. Some of the definitions in piflocal.h required definitions from the Microsoft standard header file WinSock2.h so the WinSock2.h file was #included into piflocal.h making it available. However when the resource compiler, as part of pulling in the various header files, attempted to process the WinSock2.h file as a part of processing piflocal.h, it ran into the __out_bcount_part_opt() macro and failed.

The __out_bcount_part_opt() macro, by the way, is part of the Header Annotations used in Windows headers.

Header annotations describe how a function uses its parameters and return value. These annotations have been added to many of the Windows header files to help you ensure that you are calling the Windows API correctly. If you enable code analysis, which is available starting with the Visual Studio 2005, the compiler will produce level 6000 warnings if you are not calling these functions per the usage described through the annotations. You can also add these annotations in your own code to ensure that it is being called correctly. To enable code analysis in Visual Studio, see the documentation for your version of Visual Studio.

These annotations are defined in Specstrings.h. They are built on primitives that are part of the Standard Annotation Language (SAL) and implemented using declspec("SAL*").

I then made the necessary source code changes to the resource.h and the piflocal.h header files so that few defines needed by pif.rc from piflocal.h were moved into resource.h and the header file piflocal.h was no longer included or pulled in by the resource compiler when compiling pif.rc.

By removing WinSock2.h from the list of header files pulled in by the resource compiler, the error no longer happened.

I do not know why this compiled with the standard Visual Studio 2013 settings and failed with targeting Windows XP and its variants.

Conclusion: if you are running into this error or similar error, more than likely you are including into the resource compiler a header file with a macro definition which is incompatible with the resource compiler.

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