[LLVMdev] LLVM Basic Program Compilation

Tim Northover t.p.northover at gmail.com
Sat Aug 2 00:37:38 PDT 2014


Hi Prakash,

The way you're trying to use LLVM seems like a very odd way to start.

The natural beginning move would be to write a C++ program that
produced a simple module and then try to execute that simple module
(maybe with lli).

But what you're doing is creating an (extremely complex!) module
(try.s) that, when executed will use LLVM again to create a much
simpler module. Rather more self-referential than I'd expect (and much
more difficult to get right, as you're discovering).

The way I'd expect you to be testing that program is:
$ clang++ `llvm-config --cxx-flags --ldflags --libs` try.cpp -otry
$ ./try 2> mymodule.ll
$ lli mymodule.ll

(You'll still get an error, because you need to define a @main
function to be able to execute a module, but it's a much simpler
error).

> gives me Program used external function '_ZN4llvm16getGlobalContextEv' which
> could not be resolved!

I'll say a bit about this error anyway. The "try.s" module produced by
your command has many dangling references to all the functions it
refers to from the LLVM libraries. It's the equivalent of a plain
object file ("clang -c xyz.c") and hasn't been linked at all, so you
shouldn't expect to be able to execute it directly (without more
work).

Cheers.

Tim.



More information about the llvm-dev mailing list