I am new to LLVM and what I am trying to do is to get a very simple “hello-world” C++ program to compile to LLVM IR and then to run it using lli tool.
So here is the program code (hello.cpp):
int main (int argc, char *argv)
std::cout << “Hello World!\n”;
Below are the steps I do to achieve that goal:
(+Lang for JIT/interpreter questions)
Hi Igor, not sure if that will work, but have you tried lli -jit-kind=orc-lazy ? The default is still MCJIT:
No, I haven’t. Will try that later tonight.
I just tried it. Here is what I got:
PS C:\Users\giv_u\source\repos\ConsoleApplication1\ConsoleApplication1> lli -jit-kind=orc-lazy .\ConsoleApplication1.bc
Assertion failed: isa(Val) && “cast() argument of incompatible type!”, file C:\dev\llvm-project\llvm\include\llvm/Support/Casting.h, line 264
Interesting… not stacktrace?
Correct. There is not stack trace. App exists shortly after the failed assert with exit code 3.
I just tried the -jit-kind=orc-lazy with lli executable and it solves the problem on Ubuntu 18.04 (still does not work on Windows 10). But this solution is good enough for me now. Thanks again for your help!
Regarding that stack trace: C++ code and interactions with the C++ standard library are not as well supported as C/libC, especially on Windows.
What happens if you write your hello-world program in C using printf?
Does your use-case require C++?
I have tried the same program but using stdio.h and printf(). It works fine on Windows.
But my use-case requires C++ support. I currently have a C++ text editor app in the App Store and I am working on adding on-device compilation and running capabilities (ideally). The reason for C++ support is because I believe there is a large community of people who are studying C++ in school and they would appreciate the convenience of entering and running their code on their iOS device.
the convenience of entering and running their code on their iOS device.
Off-topic FYI: Not sure if this may have changed in the meantime, but in the past iOS didn’t allow 3rd-party Apps to run JIT-compiled code.