MDK Keil 5 中文字符串 编译错误

2018-05-1117:01:51 评论 2,765 views

网上搜索到的一个问题案例:

MDK 无法编译某些中文字符串
目前用的MDK版本是最新的5.14;
程序代码:
const char *p = "我";
编译时提示:
..\User\main.c(59): error: #8: missing closing quote const char *p = "鎴?;
按照提示是缺少了一个引号,Encoding 改成 UTF-8也一样;
const char *p = "我们";
可以正常编译,没有出错。求解?


解决方法:

本人也遇到类似问题,Keil 4 编译带中文字符串程序正常,更新使用 Keil 5之后,编译报错。
在网上查看了相关问答,没有较好解决问题,因此将解决方法分享给大家:编译时,添加编译选项:--no-multibyte-chars,控制编译器不处理多字节编码字符:

 

 

官方说明: http://www.keil.com/support/man/docs/armcc/armcc_chr1359124934197.htm

--multibyte_chars, --no_multibyte_chars

7.110 --multibyte_chars, --no_multibyte_chars

Enables and disables processing for multibyte character sequences in comments, string literals, and character constants.

Default

--multibyte_chars is the default, but the option only has an effect in locales that use multibyte characters.

Usage

Multibyte encodings are used for character sets such as the Japanese Shift-Japanese Industrial Standard (Shift-JIS).

Note

If the source file encoding is UTF-8 or UTF-16, and the file starts with a byte order mark then the compiler ignores the --locale and --[no_]multibyte_chars options and interprets the file as UTF-8 or UTF-16.

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: