Embed cling

Hi all,

i want to embed cling into a c+±application, but is there something like a best way?

i’ve searched all .so’s, but cling doesnt seem to have one lib to link against:

find . -name "*.so" | xargs du -h
36K     ./Debug+Asserts/lib/libprofile_rt.so
256K    ./Debug+Asserts/lib/BugpointPasses.so
211M    ./Debug+Asserts/lib/libclang.so
96K     ./Debug+Asserts/lib/LLVMHello.so
138M    ./Debug+Asserts/lib/libLTO.so

best regards,


use the libs that are used to link cling (the executable) - you can see that by running

touch tools/cling/tools/driver/cling.cpp
make VERBOSE=1

They are all static libs - but that shouldn’t matter when embedding in your executable.

Cheers, Axel.

Thank you very much, again! :slight_smile:

With the help of make VERBOSE=1 i built my own application now.

I have copied this files in ./embed/:

  • llvm/tools/cling/tools/driver/RequiredSymbols.cpp
  • llvm/tools/cling/tools/driver/cling.cpp renamed to embed.cpp

Then i’ve setup compile.sh with the help of the make-output and changed the directories, so the object-files are build into the current directory.



RequiredSymbols.cpp RequiredSymbols.d.tmp RequiredSymbols.o cling.d.tmp compile.sh embed.cpp embed.elf embed.o[/code]

The problem is now:

./embed.elf: error while loading shared libraries: libLLVM-3.2svn.so: cannot open shared object file: No such file or directory

Ok, thats simple to fix, i just want to preload the .so instead of install it:

LD_PRELOAD=/root/cling4/llvm/Release/lib/libLLVM-3.2svn.so ./embed.elf
TESTmuhaha!!! xDD a=0x0b53c8a0!
ERROR in cling::CIFactory::createCI():
  resource directory /root/cling4/llvm/tools/cling/lib/clang/3.2 not found!

****************** CLING ******************
* Type C++ code and press enter to run it *
*             Type .q to exit             *

Ok, running, but it cant find the resource directory now. The normal “cling” just works fine.

Does anybody know how to tell ./embed the resource directory?

Best regards,


See the llvmdir parameter to the Interpreter constructor. It needs the files in lib/clang/3.2/ and you’ll need to pass the containing lib directory.

Cheers, Axel.