# Building clang

**URL:** https://discourse.llvm.org/t/building-clang/56198
**Category:** Clang Frontend
**Created:** [August 15, 2020, 10:28am UTC](https://discourse.llvm.org/t/building-clang/56198 "2020-08-15T10:28:38Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![denis\_gantsev](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@denis\_gantsev](https://discourse.llvm.org/u/denis_gantsev)
#### Post date: [August 15, 2020, 10:28am UTC](https://discourse.llvm.org/t/building-clang/56198/1 "2020-08-15T10:28:38Z")

</div>

Hi,  
I wanted to play with clang, and was trying to build it according to instructions ([https://clang.llvm.org/get\_started.html](https://clang.llvm.org/get_started.html)), with GCC 5.5 and GNU ld 2.26.1, running my linux 5.6.7.

However, the build regularly fails, running out of memory (my laptop has 12Gb RAM). I tried with both “Unix Makefiles” and “Ninja 1.7.1”. I did specify explicitly “`DLLVM_ENABLE_PROJECTS=clang`”.

Is it expected to consume that much memory during build?

Regards,

Denis

---

<div class="post-metadata">

### Author: ![DimitryAndric](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/dimitryandric/32/2082_2.png) [@DimitryAndric](https://discourse.llvm.org/u/DimitryAndric)
#### Post date: [August 15, 2020, 11:14am UTC](https://discourse.llvm.org/t/building-clang/56198/2 "2020-08-15T11:14:47Z")

</div>

What usually helps a lot is to add the following to your initial CMake invocation:

-D LLVM\_PARALLEL\_LINK\_JOBS=1

Since linking tends to use lots of memory, and is rather slow, these jobs usually end up clustered together near the end of build stages, and will then fill up all available memory. Limiting the number of parallel link jobs usually helps with this problem.

-Dimitry

---

<div class="post-metadata">

### Author: ![dblaikie](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/dblaikie/32/977_2.png) [@dblaikie](https://discourse.llvm.org/u/dblaikie)
#### Post date: [August 15, 2020, 5:21pm UTC](https://discourse.llvm.org/t/building-clang/56198/3 "2020-08-15T17:21:53Z")

</div>

GNU ld probably is a bit of a bottleneck here - try gold or lld if you can.

But also what Dimitry said - about reducing the number of link steps.  
Also depends if you build with debug info - that adds a lot. Using  
Split DWARF can help ease that a bit.

---

<div class="post-metadata">

### Author: ![denis\_gantsev](https://avatars.discourse-cdn.com/v4/letter/d/77aa72/32.png) [@denis\_gantsev](https://discourse.llvm.org/u/denis_gantsev)
#### Post date: [August 15, 2020, 8:23pm UTC](https://discourse.llvm.org/t/building-clang/56198/4 "2020-08-15T20:23:02Z")

</div>

Hi  
Thanks to everyone, indeed, using “-DLLVM\_PARALLEL\_LINK\_JOBS=1 -DLLVM\_USE\_LINKER=gold -DLLVM\_TARGETS\_TO\_BUILD=X86”, actually worked!  
P.S I had to turn off swap completely, because I prefer process being killed than my laptop being unusable

Thanks again

Regards  
Denis

---

<div class="post-metadata">

### Author: ![Whisperity](https://sea1.discourse-cdn.com/flex021/user_avatar/discourse.llvm.org/whisperity/32/20091_2.png) [@Whisperity](https://discourse.llvm.org/u/Whisperity)
#### Post date: [August 15, 2020, 8:30pm UTC](https://discourse.llvm.org/t/building-clang/56198/5 "2020-08-15T20:30:36Z")

</div>

In addition, if you can stomach slower load times but faster builds, you can also use -DBUILD\_SHARED\_LIBS=ON

denis gantsev via cfe-dev \<[cfe-dev@lists.llvm.org](mailto:cfe-dev@lists.llvm.org)\> ezt írta (időpont: 2020. aug. 15., Szo, 22:23):
