Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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).

like image 519
Matěj Zábský Avatar asked Mar 22 '15 12:03

Matěj Zábský


1 Answers

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.

like image 141
simurg Avatar answered Oct 07 '22 07:10

simurg