gcc编译报错:程序中有游离的‘\357’‘\273’‘\277’等 解决方法
原文:https://www.cnblogs.com/lidp/archive/2009/06/17/1697886.html
1. 程序(*.c,*.h)中使用了中文的标点符号(全角),比如;,},+。
改成英文的标点半角符号就行了。
甚至有时候空格也会出现类似错误,删掉该空格 重新输入。
vim里面做类似替换还是很容易的。
如何看到报错的符号?
od -c hello.c > log.txt
在log中就能看到符号了
2.
如果替换成了英文标点还出错的话,还报此错误,那么就是文件存贮格式的问题了。
一般在windows下的文件都存成ansi格式,为了在linux下能通用,建议保存成UTF-8不带BOM
编码格式,因为目前gcc和g++不支持UTF-8带BOM编码格式。
用g++编译的时候碰到UTF-8 BOM错误怎么办?
$ g++ -I../../include unit_test.cpp -o unit_test
unit_test.cpp:1: 错误: 程序中有游离的'\357'
unit_test.cpp:1: 错误: 程序中有游离的'\273'
unit_test.cpp:1: 错误: 程序中有游离的'\277'
In file included from unit_test.cpp:63:
...
或在英文系统下:
$ g++ -I../../include unit_test.cpp -o unit_test
unit_test.cpp:1: error: stray '\357' in program
unit_test.cpp:1: error: stray '\273' in program
unit_test.cpp:1: error: stray '\277' in program
In file included from unit_test.cpp:63:
...
如何判断文件是否是使用UTF-8 BOM存储的?
执行下面的命令:
$ cat cpp/src/unit_test/unit_test.cpp |hd -n 10
00000000 ef bb bf 2f 2a 2a 2a 2a 2a 2a |.../******|
0000000a
最后更新:2017-04-02 06:51:59
上一篇:
java.lang.UnsatisfiedLinkError: Can't load library from JNI code
下一篇:
创新源于模仿之五:做一个自己的QuickAction
移动互联网的入口之争
《Linux From Scratch》第二部分:准备构建 第五章:构建临时文件系统- 5.29. Perl-5.20.2
C/C++数组和指针详解
看阿里云窄带高清如何支援优酷 让《楚乔传》更清晰
阿里上班不打卡,任性进内网,全靠一个“男人”?!
奖励用户吐槽 阿里云的“用户回家计划”意欲何在?
HDU1173 采矿
android中google“定位查询”编辑
94倍性能进化!阿里云企业级ECS发布会推出最新一代异构计算产品
Eclipse的JSP页面提示Multiple annotations found at this line或者String cannot be resolved to a type