C++ Linux下Visual Studio与gcc的兼容性
我试图在 Linux 下使用 QtCreator 构建一个用 VS 2008 编写的项目,但出现大量错误:
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: error: stray ‘\377’ in program
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: error: stray ‘\376’ in program
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: error: stray ‘#’ in program
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: warning: null character(s) ignored
等等。
这是否意味着编译器无法正确处理 unicode?我该如何修复它?
I am trying to build a project written in VS 2008 using QtCreator under Linux and I get loads of errors:
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: error: stray ‘\377’ in program
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: error: stray ‘\376’ in program
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: error: stray ‘#’ in program
/home/ga/dev/CppGroup/MonteCarlo/main.cpp:1: warning: null character(s) ignored
etc.
Does it mean that the compiler can't handle unicode correctly? How can I fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这看起来像是小端 UTF-16 的 UTF-16 BOM。您需要确保文件保存为 UTF-8 或通过 iconv -f UTF-16LE -t UTF8 myfile 手动转换。
That looks like a UTF-16 BOM for little-endian UTF-16. You need to make sure the file is saved as UTF-8 or convert it manually via
iconv -f UTF-16LE -t UTF8 myfile
.确保文件采用 UTF-8 编码。使用允许您选择文件编码(例如 gedit 或 notepad++)的文本编辑器打开它并进行转换。我以前也遇到过类似的问题,但 UTF-8 文件工作正常(其他编码如 UTF-16 则无法工作)。
编辑:不要将资源脚本(如果有)转换为 UTF-8。资源编译器将无法读取它(至少在使用 MSVC 2008 时)。
Ensure the file is encoded in UTF-8. Open it with a text editor that allows you chosing the file encoding (e.g. gedit or notepad++) and convert it. I've had similar issues before, but UTF-8 files work fine (other encodings like UTF-16 won't work).
Edit: Don't convert your resource script (if there's any) to UTF-8. The resource compiler won't be able to read it (at least when using MSVC 2008).
可能是你的文件使用windows编码,带有^M、\r\n...等字符
在编译之前您是否尝试过在源文件上运行 dos2unix ?
It may be that your files use windows encoding, with characters like ^M, \r\n...
Have you tried to run dos2unix on your source files before compiling ?
我想我在带有 unicode 的文件中看到了“stray ...”。
您可以配置编辑器或控制台(或两者)的编码设置来修复它。
I think i've seen 'stray ...' in file with unicode.
You may configure your editor's or console's (or both) encoding setting to fix it.