Search code examples
cling

How to use Cling to tinker with a large C++ library in a REPL?


Cling sounds like a great way to tinker around with a the API of a large library for learning purposes. Unfortunately, there is no documentation or tutorials on how to even get started with this. I kept running into missing symbols, and having to use C++filt and rgrep over the sources over and over again to figure out what library or header to load, until I gave up.

Is the right strategy to JIT the entire library from the sources, or should you link in a pre-built library?


Solution

  • One way to make the link between headers and libraries is generating an autoloading map (http://cling.web.cern.ch/cling/doxygen/classcling_1_1Interpreter.html#ad56b40974d204f85e9fc0a9fa9af1660). One can generate it at built time and add a hook in the library during its static initialization. Thus the user would do: .L myLib This in turn would trigger header inclusion. The other way is a bit more trickier. Have a look at https://github.com/vgvassilev/cling/tree/master/test/Autoloading

    I hope it helps.