How to diagnose g++ error "cc1plus.exe: out of memory allocating 838860800 bytes" in moderately sized project?

13,225

That happens when you try to compile a UTF-16 encoded file saved in Windows with gcc. Change encoding of your sources to UTF-8. See related CPP documentation.

Share:
13,225
Matěj Zábský
Author by

Matěj Zábský

Working as C# developer at Tollnet a.s. Check out my pet project - GeoGen (programmable procedural heightmap generator). My blog LinkedIn profile GitHub profile

Updated on July 11, 2022

Comments

  • Matěj Zábský
    Matěj Zábský almost 2 years

    I'm attempting to port my C++ library to g++ using rudimentary makefile (it compiles well in Visual Studio). The portion I'm trying to compile right now measures at about 45000 lines of code.

    The library itself compiles OK, but when I attempt to include it into a console iterface application, the compiler crashes with following message and nothing else:

     cc1plus.exe: out of memory allocating 838860800 bytes
    

    It happens when I include the main header of the project (which is machine generated and is not committed to the repo, see it here on Gist).

    I figured it is because the header is too large, but I noticed other projects have all-encompassing headers like this and don't suffer from these issues. I tried to strip down all non-essentials (to about 1/3rd, the rest was necessary for the application to compile) from the header and the problem persevered. I also noticed the number in the error message did not change at all, so I believe there is some singular issue causing the error, rather than it being caused by sheer volume of code.

    There is very little template usage beyond usual STL and the code I'm compiling doesn't seem to be remarkable in any way.

    I'm using g++ 4.8.1 under mingw32 on Windows 8.1 x64 with 16 GB of RAM. The code is being compiled with -std=c++98.

    How can I locate the code which is causing this issue? g++ doesn't provide me with any diagnostic information to suggest the cause, even with the -v switch (here is what it returns).

  • Matěj Zábský
    Matěj Zábský about 9 years
    Thanks! The main header was indeed written in UTF16 by the script I use to generate it. Who would have thought incorrect encoding would cause GCC to allocate 800 MB of RAM.