llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.39k stars 11.73k forks source link

Failed to compile llvm on a windows machine with default code page as 936 #64668

Open RichardUSTC opened 1 year ago

RichardUSTC commented 1 year ago

Hello, I am compiling LLVM 16.0.6 on a Windows machine with Visual Studio. The system language is Simplified Chinese and thus the default code page is 936.

During the compiling process, I encountered some warning and error messages as follows:

clang\lib\Lex\UnicodeCharSets.h(1,1): warning C4819: 该文件包含不能在当前代码页(936)中表示的字符。请将该文件保存为 Unicode 格式以防止数据丢失 (编译源文件 clang\lib\Lex\Lexer.cpp) [tools\clang\lib\Lex\obj.clangLex.vcxproj]
  RewriteRule.cpp
  ChromiumCheckModel.cpp
clang\lib\Lex\UnicodeCharSets.h(394,1): error C2226: 语法错误: 意外的“llvm::sys::UnicodeCharRange”类型 (编译源文件 clang\lib\Lex\Lexer.cpp) [tools\clang\lib\Lex\obj.clangLex.vcxproj]
clang\lib\Lex\UnicodeCharSets.h(394,69): error C2143: 语法错误: 缺少“;”(在“{”的前面) (编译源文件 clang\lib\Lex\Lexer.cpp) [tools\clang\lib\Lex\obj.clangLex.vcxproj]
  SourceCode.cpp
clang\lib\Lex\UnicodeCharSets.h(394,69): error C2447: “{”: 缺少函数标题(是否是老式的形式表?) (编译源文件 clang\lib\Lex\Lexer.cpp) [tools\clang\lib\Lex\obj.clangLex.vcxproj]

In a word, the compiler complains that the source file cannot represent some unicode charaters in code page 936.

I finally fixed the problem by adding -DCMAKE_C_FLAGS="/utf-8" -DCMAKE_CXX_FLAGS="/utf-8" to the cmake command line. I hope that you can add the '/utf-8' flags directly in the CMakeLists.txt by default.

llvmbot commented 1 year ago

@llvm/issue-subscribers-clang-frontend

cor3ntin commented 1 year ago

I'm surprised we don't already do that. We should definitively compile with /source-charset:utf-8 under MSVC

cor3ntin commented 1 year ago

https://reviews.llvm.org/D157986