Issue in Kaleidoscope compilation in chapter 4


I am new to LLVM and trying to explore the Kaleidoscope tutorial. I am getting an issue while running the code from llvm example.

clang++ -g toy.cpp `llvm-config --cxxflags --ldflags --system-libs --libs core orcjit native` -O3 -o toy

I am getting the following error -

In file included from toy.cpp:1:
./../include/KaleidoscopeJIT.h:97:12: error: use of undeclared identifier 'ExecutorSymbolDef'
  Expected<ExecutorSymbolDef> lookup(StringRef Name) {
./../include/KaleidoscopeJIT.h:98:12: error: no viable conversion from returned value of type 'Expected<llvm::JITEvaluatedSymbol>' to function return type 'int'
    return ES->lookup({&MainJD}, Mangle(Name.str()));
2 errors generated.

I could not understand what shall I change so this will work. Can you please help me to understand the issue?

If I understand correctly, the switch to using ExecutorSymbolDef is recent: [ORC] Move most ORC APIs to ExecutorAddr, introduce ExecutorSymbolDef. · llvm/llvm-project@8b1771b · GitHub

Perhaps @lhames can help?

You mention that you are on chapter 4, do the other chapters compile correctly for you?


Yes, you are right. It is a recent change. The previous chapter’s code for Kaleidoscope is working fine. However, I tried chapters 4 and 5 and got the same issue.
This issue is coming from KaleidoscopeJIT.h file from the below code -

Expected<ExecutorSymbolDef> lookup(StringRef Name) {
    return ES->lookup({&MainJD}, Mangle(Name.str()));

Thanks @Sudip, @DavidSpickett. I’ve added the missing ExecutorSymbolDef.h header in 13f5125f9d86. Could you try building the examples again using top-of-tree?

Thanks @lhames for the quick patch. I took the latest code, however, it is failing with a different error. Before posting here, I tried updating the missing header and it was giving me the same error which I am getting now.

In file included from toy.cpp:1:
./../include/KaleidoscopeJIT.h:25:10: fatal error: 'llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h' file not found
#include "llvm/ExecutionEngine/Orc/Shared/ExecutorSymbolDef.h"
1 error generated.

I could not understand why it is not finding the header file even though the file is there.

I am not sure what is going on here.

You could try running make / ninja with the -v option to confirm that the expected include directories are being passed to the compiler (however if this was not correct I’d expect other errors).

It may also be worth reconfiguring and rebuilding LLVM in case this is some sort of misconfig.

I have run into the same issue. When I build LLVM locally, from source, the file is found. However, when I install LLVM using the apt-get packages, that file does not exist, while all the rest works even with the apt version of those packages.

Apparently, this file has been added more recently than version 15, which is the latest LLVM package I can find on Ubuntu.

The following fixes the issue, tested on GitHub Actions too:

chmod +x
sudo ./ 18

(It doesn’t work till version 16, works in 18, didn’t check 17. If it still doesn’t work, check the env-variable LLVM_PACKAGE_VERSION, and if it’s not v18 then run sudo apt-get remove -y llvm-12 lldb-12 llvm-12-dev libllvm12 llvm-12-runtime in case the version found is v12)