Running out of memory building flang

I cloned the llvm project and followed the directions for building flang via cmake and ninja. It appears to build llvm just fine. I think it builds mlir fine, but building flang uses up all available app memory on my system while building Coarray.cpp.o from here:


I’m on a 2013 MacPro with 12GB RAM. Not the beefiest machine, but not terrible. Is there a way to get it through this without adding more RAM to my system? I’m running no apps other than, though there is a large TimeMachine backup running, which might be interfering a little bit.

It should not be impossible to build flang with 12 GB of memory, but it might take a while. There are many demanding translation units in flang, and building several of them simultaneously easily becomes too much for an old workhorse. It is probably necessary for you to reduce the amount of parallelism in your build. To put a cap on the number of parallel compiles, use ‘ninja -j2’ (or any other number). It might be worth setting -DLLVM_PARALLEL_LINK_JOBS=1, as linking tends to be particularly memory-demanding. See also Getting started - common problems for some more tips.

Your activity monitor should give you some insight into what is going on. Is it a clang that is consuming memory? Are there several clangs? Is the linker ld the culprit?

OK, I’ve started another build using ninja -j2, and it seems to be chugging along. Activity Monitor showed several instances of clang running before (looked like 6 or 8, so ~1 per core) now it shows only 2. So think that was likely it! Thank you for your help!

Yep! That did it. I now have the compiler working. Thank you!