<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<br>
<br>
On 03/01/2012 09:24 PM, Christopher Jones wrote:
<blockquote
cite="mid:CAKiKb62H=VH89V6Jp9+LcLg2v3GE_mkyHbePw1qZ2fkgS+cqQg@mail.gmail.com"
type="cite">Hello all,
<div><br>
</div>
<div>I'm brand new to using LLVM and am having trouble using lli
with a C++ program. I tried to compile the following:</div>
<div><br>
</div>
<div>
<div>#include<iostream></div>
<div>using namespace std;</div>
<div>int main()</div>
<div>{</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>cout
<< "Hello, world!" << endl;</div>
<div><span class="Apple-tab-span" style="white-space:pre"> </span>return
0;</div>
<div>}</div>
</div>
<div><br>
</div>
<div>When I compile directly to an executable with the following
command, all is well:</div>
<div>$ clang++ -O3 hello.cpp -o hello</div>
<div><br>
</div>
<div>But when I try to produce a bitcode file, I get an error:</div>
<div><br>
</div>
<div>$ clang++ -O3 -emit-llvm hello.cpp -c -o hello.bc</div>
</blockquote>
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.<br>
<br>
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.<br>
<br>
-Matt<br>
<br>
<blockquote
cite="mid:CAKiKb62H=VH89V6Jp9+LcLg2v3GE_mkyHbePw1qZ2fkgS+cqQg@mail.gmail.com"
type="cite">
<div>$ lli hello.bc</div>
<div>LLVM ERROR: Program used external function
'_ZSt16__ostream_insertIcSt11char_traitsIcEERSt13basic_ostreamIT_T0_ES6_PKS3_l'
which could not be resolved!</div>
<div><br>
</div>
<div>I'm running this on x86_64. I'd appreciate any help about
what I'm doing wrong.</div>
<div>Thanks!</div>
<div><br>
</div>
<div>Chris</div>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<br>
<pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a> <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
</blockquote>
</body>
</html>