[LLVMdev] (Newbie) Using lli with clang++?

Matt Johnson johnso87 at crhc.illinois.edu
Thu Mar 1 22:14:08 PST 2012



On 03/01/2012 09:24 PM, Christopher Jones wrote:
> Hello all,
>
> I'm brand new to using LLVM and am having trouble using lli with a C++ 
> program.  I tried to compile the following:
>
> #include<iostream>
> using namespace std;
> int main()
> {
> cout << "Hello, world!" << endl;
> return 0;
> }
>
> When I compile directly to an executable with the following command, 
> all is well:
> $ clang++ -O3 hello.cpp -o hello
>
> But when I try to produce a bitcode file, I get an error:
>
> $ clang++ -O3 -emit-llvm hello.cpp -c -o hello.bc
hello.bc doesn't contain the libstdc++ bits your program needs (iostream 
and its (many) dependencies).  When you produce an executable, clang 
tells the linker to link your binary with libsupc++, libstdc++, and 
others, so the dynamic linker can satisfy your iostream dependencies at 
runtime.  When running under lli, the interpreter will provide *a few* 
basic functions for you (see 
lib/ExecutionEngine/Interpreter/ExternalFunctions.cpp), but things like 
exit(), abort(), printf(), and scanf(), nothing as complicated as 
libstdc++.  So if the function you need is not in the short list 
provided by the interpreter itself, it will try to find your function 
using libffi (if you compiled it in).  If that doesn't work, you'll get 
errors like the below.

One solution would be to try to generate a single big .bc file that is 
"statically linked" with all your dependencies (for some clues as to 
what these are, try "ldd ./hello" on your clang++-generated binary.  
Unfortunately, I'm no expert on this or any other methods of informing 
lli about your .bc file's dependencies and where they can be found when 
your interpreted program calls out to them.

-Matt

> $ lli hello.bc
> LLVM ERROR: Program used external function 
> '_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l' 
> which could not be resolved!
>
> I'm running this on x86_64.  I'd appreciate any help about what I'm 
> doing wrong.
> Thanks!
>
> Chris
>
>
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20120302/3512bb0e/attachment.html>


More information about the llvm-dev mailing list