[embedded] cling crashing/segfaulting on minimal useage

#include <iostream>
#include <string>

#include <cling/Interpreter/Interpreter.h>

static const std::string PATH_TO_LLVM {"/home/d4nf/cling/prefix/"};
static const char * clingArgs[] = {"", "-std=c++11"};
int main()

    cling::Interpreter inter(2, clingArgs, PATH_TO_LLVM.c_str());
    inter.execute("#include <iostream>\n");

my errors are displayed here: bpaste.net/show/bfbd723d4daa

I don’t know what I’m doing wrong. According to cling.web.cern.ch/cling/doxygen/annotated.html , there is a programmers guide, but i don’t know where to find that.

Can I get help with this please?

Thanks in advance.

p.s. I’m not marking How to proprly link cling into my executable with cmake? as solved until It’s confirmed that no errors are caused by bad linking


You should probably use inter.declare("#include \n");

As the doc says, interp.execute() “wraps” the input and runs it; the input must be expressions only (not declarations as in your case). The use of the jargon word “wrap” is really not very useful, I’ve updated it to clarify what happens.

Cheers, Axel.

Thanks again Axel!

Going to try loading in a file. If I’m passing in a cpp file, do i need to filter the declarations out?


So there are three main interfaces for cling::Interpreter:

  • declare() is for things that don’t need to be run, e.g. #include, of void f() {}
  • execute() is for expressions that you want to run, e.g. sin(0.2) or exit()
  • process() is for either kind of input, where cling tries its best to do whatever needed.

Injecting your cpp file into cling would thus use declare() (or loadFile()).

Cheers, Axel.