在Linux上的C ++源文件上运行“gcc”给出“cc1plus:out of memory allocation ...”错误信息 [英] Running 'gcc' on C++ source file on Linux gives "cc1plus: out of memory allocating ..." error message
问题描述
在Ubuntu上使用gcc编译C ++源文件时,遇到了一个令人困惑的问题。解决了这个问题,我想在这里发布它,以节省解决它的头痛。
I encountered a puzzling problem when compiling a C++ source file using 'gcc' on Ubuntu. Having solved the problem I would like to publish it here to save others the headache of solving it.
为了本报告的目的,我们有最简单的C ++ World程序,存储在main.cpp中:
For the sake of this report we have the simplest possible C++ "Hello, World" program, stored in main.cpp:
#include <stdio.h>
int main (int argc, char *argv[])
{
return 0;
}
当我运行命令:
gcc main.cpp
错误消息:
cc1plus: out of memory allocating 1677721600 bytes after a total of 475136 bytes
我确认我正在编译正确的位元(即32位元)。我做错了什么?
I verified I was compiling for the correct bittage (i.e., 32-bit). What was I doing wrong?
推荐答案
原来我已经将C ++源文件保存为UTF-16 Unicode编码文件,在文件开头处带有前导Unicode字节顺序标记(BOM)字节。该文件在Windows系统上保存为UTF-16,提交到版本控制系统,然后签出到Linux。 gcc支持Unicode编码为UTF-8,但不支持Unicode编码为UTF-16。
It turns out I had saved the C++ source file as a UTF-16 Unicode-encoded file, complete with leading Unicode Byte Order Mark (BOM) bytes at the beginning of the file. The file was saved as UTF-16 on a Windows system, committed to a version control system, then checked out to Linux. gcc does support Unicode encoded as UTF-8, but not Unicode encoded as UTF-16.
解决方案是将源文件转换回标准的非Unicode编码。
The solution was to convert the source file back to a standard, non-Unicode encoding.
这篇关于在Linux上的C ++源文件上运行“gcc”给出“cc1plus:out of memory allocation ...”错误信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!