--- title: 解决chromium警告C4819 date: 2018-04-26 20:57:04 tags: [chromium] categories: chromium --- 初次构建chromium的时候,可能会遇到错误 > : warning C4819: The file contains a character that cannot be represented in the current code page (936). Save the file in Unicode format to prevent data loss > > : error C2220: warning treated as error - no 'object' file generated 尤其是在Windows上构建的时候,更容易遇到,网络上的方法,基本都是修改系统区域为英国(美国): > 控制面板--区域--管理--更改系统区域设置 > 在页面中选择英语区域即可 ~~这样修改系统设置,我不太喜欢,尤其是在工作机上,这样修改可能会引起其他未知问题,所以直接修改了[gn配置文件](https://chromium.googlesource.com/chromium/src.git/+/master/build/config/compiler/BUILD.gn#1161)中的`default_warnings`字段,添加一项`"/wd4819"`即可。~~ --- **Update:** 上面方法会导致部分文件无法正常解析,产生各种奇怪的语法错误。 新版chromium已经修复了此问题,提交详情见[这里](https://chromium.googlesource.com/chromium/src.git/+/663994ebf90ac57f5cc56a9639a16e29aee1ff2b%5E%21/#F0),最新的BUILD.gn文件见[这里](https://chromium.googlesource.com/chromium/src.git/+/663994ebf90ac57f5cc56a9639a16e29aee1ff2b/build/config/compiler/BUILD.gn#842),其基本原理就是VS2015支持的新特性[/utf-8](https://msdn.microsoft.com/en-us/library/mt708821.aspx),所以最终只需要在`build/config/compiler/BUILD.gn`文件中添加该编译选项即可: ```gn cflags += [ # Assume UTF-8 by default to avoid code page dependencies. "/utf-8", ] ```