Unable to get started with LLI and LLC

Hi there

I was just getting started with LLVM to create a small compiler of my own, while skimming through the docs came across the use of lli and llc in the development process, have successfully installed clang but somehow the lli and llc command are not working, I have a macOS it is showing the error “command not found” , if I try to build lli and llc with CMake it throws this error

CMake Error at CMakeLists.txt:23 (add_llvm_tool):
Unknown CMake command “add_llvm_tool”.

searched a lot around on the web to find the solution but couldn’t find it, would be a great help if there is a workaround to it.

Regards,
Jagrat Patkar

Hi Jagrat,

I was just getting started with LLVM to create a small compiler of my own, while skimming through the docs came across the use of lli and llc in the development process, have successfully installed clang but somehow the lli and llc command are not working, I have a macOS it is showing the error "command not found" , if I try to build lli and llc with CMake it throws this error

CMake Error at CMakeLists.txt:23 (add_llvm_tool):
  Unknown CMake command "add_llvm_tool".

It sounds like you might be trying to point CMake at the llc or lli
tool's own directory (/path/to/llvm-project/llvm/tools/llc). Instead
CMake has to be told to start from /path/to/llvm-project/llvm, and
then both llc and lli are targets you can ask it to build.

There's some documentation on how to build LLVM (what options you
might want and so on). https://llvm.org/docs/GettingStarted.html, and
https://llvm.org/docs/CMake.html.

Cheers.

Tim.

Hello Tim,

Thank you so much for replying, I tried building llvm from a separate build directory inside llvm-project as described in the documentation,
now i see all the tools in the build directory at least, just couldn’t figure out how do i build the specific tools lli and llc in the build directory.

I tried this out inside llvm-project/build
cmake -G Ninja tools/lli
cmake -G Ninja tools/llc

but none of it worked, although the subdirectories do exist under the llvm-project/build/tools/llc or lli

While building the whole llvm i had tried

cmake -G Ninja -DLLVM_ENABLE_PROJECTS=“clang;lli;llc” …/llvm this command which resulted in the build directory getting loaded with many subdirectories including tools directory containing lli and llc. But still it didn’t enable lli and llc even after mentioning it in the ENABLE_PROJECTS flag

Thankyou in advance!
Jagrat Patkar

I tried this out inside llvm-project/build
cmake -G Ninja tools/lli
cmake -G Ninja tools/llc

but none of it worked, although the subdirectories do exist under the llvm-project/build/tools/llc or lli

Yep, those two are never going to work. The CMakeLists.txt in those
directories aren't self-contained.

cmake -G Ninja -DLLVM_ENABLE_PROJECTS="clang;lli;llc" ../llvm this command which resulted in the build directory getting loaded with many subdirectories including tools directory containing lli and llc. But still it didn't enable lli and llc even after mentioning it in the ENABLE_PROJECTS flag

You don't need lli or llc in LLVM_ENABLE_PROJECTS because they're part
of baseline LLVM. But other than that it should have worked. What
error message did you get when you tried running "ninja llc" after
that CMake command?

Cheers.

Tim.

If I execute the following command from the build directory (llvm-project/build)

cmake -G Ninja …/llvm/tools/llc

then I am getting the following error

CMake Error: The source “/Users/jagratpatkar/Desktop/ComputerScience/llvm-project/llvm/tools/llc/CMakeLists.txt” does not match the source “/Users/jagratpatkar/Desktop/ComputerScience/llvm-project/llvm/CMakeLists.txt” used to generate cache. Re-run cmake with a different source directory.

Thanks!
Jagrat Patkar.

The following should build just llc and lli and put them in the bin subdirectory in your build directory.

cmake -G Ninja …/llvm

ninja llc lli

Executed the commands as suggested, it did build lli and llc and gave the following output

[2302/2302] Linking CXX executable bin/llc

but when I type lli or llc in the command line still it giving me command not found error

Because they are in "bin" dir?