Using the llvm D-bindings [solved]

Manuel König manuelk89 at
Wed Oct 6 07:57:09 PDT 2010

The previous "Initial setup" description didn't pass the "copy paste"
test, now it's more instructive. The same should work for llvm 2.6 and
2.8, too (yes, 2.8 was just released and the bindings are already
there :)

Initial setup:

svn co
cd llvm-2.7
./ builds Target.o and Ext.o which have to be passed
to the linker. For convenience, these *.o files are also merged
into a single library libllvm-c-ext.a.

Target.o and Ext.o are usually not needed for the regular
llvm c interface. But the D bindings add some extra bindings,
because the official c interface just doesn't expose all
functionality from the c++ interface. These are implemented as a
"c++ to c to d" bridge (c++ to c is Target.cpp and Ext.cpp, c to
d is Target.d and Ext.d).

Building your application:

To compile and link a file main.d, run

LLVM_LIBS=`llvm-config --libs | sed 's/-l/-L-l'`
ldc -I=$LLVMD \
    $LLVM_LIBS \
    -L=$LLVMD/libllvm-c-ext.a \
    -L-ldl -L-lstdc++ -relocation-model=pic \
LLVM_LIBS                 a list of all llvm libraries, formatted for
ldc -L=$LLVMD/libllvm-c-ext.a only needed when you use Target.d or Ext.d
-L-lstdc++                links in the c++ standard library (llvm at
it's core is c++) -relocation-model=pic     necessary for calling code
in your app from inside of the llvm vm

More information about the Digitalmars-d-learn mailing list