2

I haven't really found a solid answer to this question other than "get more ram". Is there a way to reduce the memory used by g++ during the compile process? I am (for reasons) trying to compile webkitgtk on a g4 mac mini with 1GB ram. It can't be upgraded. Current compilation options are -Os -mabi=altivec -mcpu=native -mtune=native. It has 1GB ram and 1GB swap but just runs out of memory. While I could theoretically just keep adding swap space, in practice this gets very slow, and I want to minimize that.

Raven King
  • 155
  • 1
  • 12
  • 2
    You have a coding problem, not a gcc problem. You can try using more forward declarations instead of .h file inclusions in your .h files, hiding implementations using the pimpl idiom, and reducing the usage of templates (and boost!). – Shloim Dec 25 '19 at 15:28
  • Some day I hope to know enough about c and c++ to make useful edits like that. Not there yet though. – Raven King Dec 25 '19 at 15:36
  • 1
    You could add more swap (some 16+GB). It will be insanely slow, but *should* allow the compilation to finish). – Jesper Juhl Dec 25 '19 at 15:36
  • @JesperJuhl ultimately that is what I will need to do, however I was hoping there was some way I can reduce the amount required. – Raven King Dec 25 '19 at 15:37
  • 3
    @RavenKing as Shloim said, you can make more use of forward declarations, remove unnecessary includes, reduce template usage (utilize extern templates) etc, to ease the pain. But at the end of the day you have to accept that compiling any significantly sized modern C++ program simply is quite memory intensive. And A 1GB ram/1GB swap machine *really* is *quite* underpowered for development work in 2019.. – Jesper Juhl Dec 25 '19 at 15:41
  • 1
    Smaller compilation units. – xaxxon Dec 25 '19 at 15:59

1 Answers1

1

Webkitgtk is notoriously demanding of RAM (and time) during compilation. The Webgtk build instructions link to some suggestions, which might be useful. But the overall impression those pages give is that you need considerably more than 1GB of RAM, unless you are prepared to let the build run for some time, possibly days.

Perhaps you have access to one or more other computers. In that case, you could consider setting up cross-compilation environments and maybe even installing distcc in order to make use of these additional resources.

Setting up a cross-compilation environment for an OS X target is a bit of a project, but once you've got that set up distcc is pretty straightforward. And it won't take very many compiles to pay back your investment in time through significantly reduced compile times.

rici
  • 234,347
  • 28
  • 237
  • 341