"Host compiler does not support '-fuse-ld=lld'" Error when running CMake command that used to work

I used to run the following CMake command:

cmake -S llvm -B build -G Ninja
-DLLVM_ENABLE_PROJECTS=“clang”
-DLLVM_ENABLE_RUNTIMES=“libcxx;libcxxabi”
-DCMAKE_BUILD_TYPE=Release
-DLLVM_USE_LINKER=“lld”
-DLLVM_ENABLE_ASSERTIONS=“ON”
-DLLVM_PARALLEL_LINK_JOBS=1
-DLLVM_TARGETS_TO_BUILD=“RISCV;X86”

and it used to successfully produce the build.ninja file and successfully compile all ninja targets.
Now, if this command is executed, I get the error “Host compiler does not support ‘-fuse-ld=lld’”.
I have tried building from the tag llvmorg-15.0.1 (my base tag) and it still produces it.

Which compiler are you using to build LLVM?

This is the option that causes the error: it requires ld.lld to exists, you probably needs to install lld first.

It is also possible that the host compiler does not support the -fuse-ld option, in which case you probably should install clang first. I personally configure cmake with -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_ENABLE_LLD=ON.
Note you need to wipe out the build directory when changing the host compiler.

Yes, I erased the build directory and after rerunning the CMake command everything was back to normal.
It is unfortunate that the solution is to erase the build directory.
And I am pretty sure that I did not change the host compiler.

2 Likes

Probably CMakeCache.txt was just caching broken state from a previous attempt.

1 Like