Ubuntu installs clang15 error

I built clang/LLVM in ubuntu20.04 by downloading the llvm-project of github. According to the construction process of the official website, I executed the last step. When I executed the make command, an error was reported:

...
[ 95%] Building C object tools/llvm-c-test/CMakeFiles/llvm-c-test.dir/metadata.c.o
[ 95%] Building C object tools/llvm-c-test/CMakeFiles/llvm-c-test.dir/object.c.o
[ 95%] Building C object tools/llvm-c-test/CMakeFiles/llvm-c-test.dir/targets.c.o
[ 95%] Linking CXX executable ../../bin/llvm-c-test
collect2: fatal error: ld terminated with signal 11 [Segmentation fault], core dumped
compilation terminated.
make[2]: *** [tools/dsymutil/CMakeFiles/dsymutil.dir/build.make:335: bin/dsymutil] Error 1
make[2]: *** Deleting file 'bin/dsymutil'
make[1]: *** [CMakeFiles/Makefile2:91054: tools/dsymutil/CMakeFiles/dsymutil.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
[ 95%] Built target llvm-c-test
[ 95%] Built target llc
[ 95%] Built target bugpoint
make: *** [Makefile:152: all] Error 2

how to solve this problem?

It depends:

  • are you running out of memory?
  • what is your cmake invocation?

https://llvm.org/docs/CMake.html#frequently-used-cmake-variables

Another option is to install lld: Building LLVM with CMake — LLVM 16.0.0git documentation

if you do cmake -G Ninja ..., then you can build with ninja which is faster than make.

Minimal and efficient:

> cmake -DCMAKE_BUILD_TYPE=Release -DLLVM_TARGETS_TO_BUILD="X86" -DCMAKE_INSTALL_PREFIX=YOURPREFIX -G Ninja -DLLVM_ENABLE_PROJECTS="clang" -DLLVM_USE_LINKER=lld ./llvm
> ninja -j X install-clang

large X for ninja are fast but will consume a lot of memory. up to you. small X are slower and need less memory.

The output of ld --version would also be helpful.

thank you,I use “make -j4” first,according to your opinions, I try “make -j2”, it useful!!!