How can I compile LLVM for windows on ubuntu or windows

In fact, all I need is clangd.exe.
How can I compile to get it ?

I’d have thought clangd would be part of the release packages, which you could just download; but I’m not sure exactly what’s in them.
You could read through [clang’s getting-started instructions[(Clang - Getting Started) which will help you figure out how to build things.
It would be simplest to build LLVM for Windows on Windows. Cross-builds get complicated.

1 Like

I know that cross-build is complex, but it must be done. Is there a similar demo here

I’d have thought clangd would be part of the release packages, which you could just download; but I’m not sure exactly what’s in them.

It is indeed. I checked LLVM-15.0.7-win64.exe - Releases · llvm/llvm-project · GitHub but I also recall clang-tools-extra being specified by test-release.sh.

I think it’s -DLLVM_ENABLE_PROJECTS="clang;clang-tools-extra" to build it yourself.

take Ubuntu 20.04 for example

first, git clone the llvm project from github:

git clone https://github.com/llvm/llvm-project.git

Second, create a folder names “build” under llvm like:

 ~/llvm-project-15.0.0
    |--- build
    |--- llvm
        |--- lib
        |--- tools
        ...

enter the build folder, and input this to init built configuration:


cmake -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang -DCMAKE_BUILD_TYPE=Debug -G "Unix Makefiles" ../llvm

then begin to built:
make

Also, you can try ninja instead of Unix Makefiles
if ubuntu tells you there are some tools missing, please use command apt install XXXXX to install support tools that needed in built.

After built , the clang tool is ready, you can enter the bin folder under the build folder, and use command clang --version to check.

By the way, if you only want to use the function of clang and have no interest on its code, why don’t you install the ubuntu clang ? only by apt install clang