out of memory allocating

Pages: 12
I get the following error:

1
2
3
cc1plus.exe: out of memory allocating 105621144 bytes
make: *** [main.o] Error 1
"make all" terminated with exit code 2. Build might be incomplete.


I tried to Google it and do what they suggest. I have 8GB RAM memory. Nothing seems to work. What to do?
What exactly are you trying to compile?

You don't have some massive mess of many source files including the source of other source files do you?

This is bad.
1
2
#include "foo.cpp"
#include "bar.cpp" 
No, it is just one big source file. How to compile it?
Agreed, would need to know just how big the main compilation unit becomes when everything is #included. If the exe is only 32-bit, then it might be trying to allocate beyond the 2/4 GB range.

But in case that isn't the issue, apparently another issue is this:
https://stackoverflow.com/a/29255154/
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.

https://gcc.gnu.org/onlinedocs/cpp/Character-sets.html

bchinfosieeuw wrote:
it is just one big source file.
How big are we talking about? Megabytes file size? A gigabyte?
And are you doing template meta-programming or something like that?
Last edited on
What do you mean by this: "trying to allocate beyond the 2/4 GB range"? I have already tried
bcdedit /set IncreaseUserVa 3072
then I installed Visual Studio, and tried
editbin /LARGEADDRESSAWARE "<path>/cc1plus.exe"
which changes my old executable, but a new one is not compiling still.
The main file is 1.055 kb.
I see you've done the research, good. Yes, I mean that if cc1plus.exe is a 32-bit process, it doesn't matter how much RAM you have total, because the address space of the process will still just either be 2 GB (if signed) or 4 GB (if unsigned).

Next thing to check would be the encoding of your file.
If you open the main file with Notepad, then click Save As... when does the Encoding show as in the save menu?
I cannot post it here, it is too big. But why would you want that? I am encountering a common problem. But I do not know what to do in order to compile.
Encoding recognizes as UTF-8 (zonder BOM)
(zonder means without in Dutch)
Okay, well I found one other possible cause not yet mentioned,
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56746
Using either -save-temps or -ftrack-macro-expansion=0 removes the memory hog.

What version of MinGW/GCC are you using?

(PS: I never asked for the source file, so maybe you were replying to someone else)
Last edited on
I am using
GCC 6.3.0
@Ganado, I asked for the source file, but withdrew it because I reckoned your suggestion more likely to be correct.

However, it can't do any harm, so @bchinfosieeuw, could you link to your file somewhere, preferably in its original encoding.
The problem is persisting. What to do to compile this program?
> No, it is just one big source file. How to compile it?
...
> The main file is 1.055 kb.
There's an 8KB posting limit on this forum, so if your "big" source file is just over 1KB as you claim, then posting it isn't a problem.
Unfortunately I cannot post the main file. The size is 1,055 kB.
I have not yet tried everything, for example how to use bcdedit and
editbin during Eclipse compilation?
Oh, you mean 1MB!
Sheesh, no wonder.

You need to start moving code out of the main source file and into other files.
Are you maybe using huge arrays on the stack?
You can put your code on Dropbox, Google drive... and just show the link.
Without seeing the code we can just guess.
The error is coming from the compiler, not the program. So you're trying to allocate huge fixed-length data structures somewhere.

Have a 1-megabyte source file probably doesn't help much either. Break it up into smaller files and compile each individually.
I am encountering a common problem.


You are not. I've got C++ programs here that take four hours to build and I've never seen this.
Well I have at least a 520 KB source file, albeit it's C# and not C++. It is uncommon, but it doesn't cause the compiler to crap out. I still think this is a MinGW bug (or, perhaps some template stuff is overloading the memory).

OP, if nothing else works I would download MinGW64 or another distro. Or use another compiler, clang or visual studio.

I've watched programming videos about auto-generated source code where compiling a single unit can take close to 30 minutes because of how huge the file is. But it doesn't fail the memory allocation. That's why I guess, despite the unusual circumstances, that this is an issue with the compiler.

But yes, having an MB file is insane, you should break it up into smaller units :)
Last edited on
Pages: 12