为何我的C++编译器输出构建信息时显示乱码字符?
CodeBlocks搭配GCC编译时构建信息乱码问题
使用CodeBlocks IDE搭配GNU GCC Compiler编译项目时,构建输出中出现乱码字符(示例如下),项目可正常编译,但乱码影响错误信息阅读。更换电脑后出现此问题,同课程其他同学无类似情况,怀疑是否缺少Windows语言包?
||=== Build: Debug in prac4e2 (compiler: GNU GCC Compiler) ===| C:\Users\...\producto.cpp||In function ‘void CargarProducto(Producto&)’:| C:\Users\...\producto.cpp|8|warning: format ‘%d’ expects argument of type ‘int*’, but argument 2 has type ‘long int*’ [-Wformat=]| C:\Users\...\producto.cpp||In function ‘void MostrarProducto(Producto)’:| C:\Users\...\producto.cpp|28|warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘long int’ [-Wformat=]| ||=== Build finished: 0 error(s), 2 warning(s) (0 minute(s), 0 second(s)) ===| ||=== Run: Debug in prac4e2 (compiler: GNU GCC Compiler) ===|
解决方法
- 调整CodeBlocks编码设置:打开CodeBlocks,依次进入
Settings->Editor->General settings,在Encoding下拉菜单中选择UTF-8或Windows-1252,应用设置后重启IDE尝试。 - 检查系统区域语言设置:打开控制面板的「区域」设置,切换到「管理」标签页,查看「非Unicode程序的语言」,确保设置为与系统匹配的语言(如中文简体或英文),更改后重启电脑。
- 指定GCC输出编码:编译时添加参数
-fexec-charset=GBK或-fexec-charset=UTF-8,强制GCC输出对应编码的信息,适配CodeBlocks的显示。
内容的提问来源于stack exchange,提问作者Maxi Fernandez
相关产品推荐
相关产品推荐

