我们所有的源代码都是有效的 UTF-8,但是 Windows 上的一些用户无法构建它们,因为他们的系统配置为不同的编码。
不加BOM对于源文件,是否可以告诉 MSVC 将所有源视为 UTF-8,而不管用户系统编码如何?
See MSDN's link regarding this topic (需要添加 BOM 表头)。
最佳答案
你可以试试:
add_compile_options("$<$<C_COMPILER_ID:MSVC>:/utf-8>")
add_compile_options("$<$<CXX_COMPILER_ID:MSVC>:/utf-8>")
By default, Visual Studio detects a byte-order mark to determine if the source file is in an encoded Unicode format, for example, UTF-16 or UTF-8. If no byte-order mark is found, it assumes the source file is encoded using the current user code page, unless you have specified a code page by using
/utf-8
or the/source-charset
option.
引用文献
关于visual-c++ - 是否可以强制 CMake/MSVC 对没有 BOM 的源文件使用 UTF-8 编码? C4819,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47690822/