Error RC2135 in C++ project due to UTF-8 encoding of RC file

六月ゝ 毕业季﹏ 提交于 2019-12-09 18:14:48

问题


After switching from Visual Studio 2010 to 2012 I got 10 RC2135 errors that looked rather strange in one of my C++ projects.

Error   1   error RC2135: file not found: 0x06        NamedPipesNative.rc   19  1   NamedPipesNative
Error   2   error RC2135: file not found: 1           NamedPipesNative.rc   28  1   NamedPipesNative
Error   3   error RC2135: file not found: 5           NamedPipesNative.rc   29  1   NamedPipesNative
Error   4   error RC2135: file not found: 5           NamedPipesNative.rc   30  1   NamedPipesNative
Error   5   error RC2135: file not found: 0x17L       NamedPipesNative.rc   31  1   NamedPipesNative
Error   6   error RC2135: file not found: FILEOS      NamedPipesNative.rc   37  1   NamedPipesNative
Error   7   error RC2135: file not found: 0x2L        NamedPipesNative.rc   38  1   NamedPipesNative
Error   8   error RC2164: unexpected value in RCDATA  NamedPipesNative.rc   41  1   NamedPipesNative
Error   9   error RC2135: file not found: BLOCK       NamedPipesNative.rc   43  1   NamedPipesNative
Error   10  error RC2135: file not found: VALUE       NamedPipesNative.rc   45  1   NamedPipesNative

Unfortunately I assumed this had something to do with the switch to VS 2012 (it had asked if I wanted to convert the C++ project or not), and I spent a lot of time trying to figure it out based on that assumption. But in fact it was something completely different. In the hopes of helping anyone else who runs into this problem I'll post the answer in a moment.


回答1:


As part of the switch to Visual Studio 2012 I had also updated the program version number in the .rc file using a home-made program that processed all of my AssemblyInfo.cs and .rc files, and it had changed the encoding of the .rc file from ANSI to UTF-8. And the Microsoft Resource Compiler can't read UTF-8 files properly! http://social.msdn.microsoft.com/Forums/hu-HU/vcgeneral/thread/e212069d-678e-4ac8-957f-7d60d3e1c89f

So the solution is to re-encode the .rc file as ANSI or UTF-16.




回答2:


If you promise to always hand-edit the .rc file, you could put this at beginning of it and the resource compiler will compile utf-8 like an angel,

#pragma code_page(65001)

But once the VS resource editor gets to regenerate the .rc file, it will be all messed up.




回答3:


You can also use Pre-build event command line to convert your UTF-8 source file before compiling.

Sample steps:

  1. exclude your UTF-8 file from compiling.

  2. make a copy of your UTF-8 file, rename it

  3. add an entry in the Pre-build event command line, converting the original UTF-8 file to the renamed file as UNICODE. This tool may help you.

    $(ProjectDir)\tools\uniconv.exe UTF8 $(ProjectDir)\DocumentBrowserUTF8.rc UCS2 $(ProjectDir)\DocumentBrowser.rc

  4. in your build scripts (in many cases, Visual Studio .vcxproj file), make it to compile the converted file instead of the original UTF-8 file.



来源:https://stackoverflow.com/questions/15244065/error-rc2135-in-c-project-due-to-utf-8-encoding-of-rc-file

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