Domanda

I'm adding a repl: option using cling to my makefile which will drop me into a repl to play around with my current project. I created an cling_init.cpp which pulls in all the headers and does some basic setup.

Then in my Makefile:

repl:
    cat cling_init.cpp | cling -std=c++11 // etc ...

the issue is that when I pipe in the contents, cling exits after evaluating it. I've looked for an option to pass a file to cling but I can't seem to find anything.

Is there a way to do this?

È stato utile?

Soluzione

Got it! You can pass a source file the same way as a library -l.

repl:
    cling -std=c++11 -lcling_init.cpp -llibpq.so -lliblog4cxx.so //etc ...

Fyi you also need to put the entire library names for it to work.

For doing additional setup I had to use a static block:

#include <iostream>

struct ClingInitialize {
  ClingInitialize () {
    std::cout << "initialize" << std::endl;
  }
};

static ClingInitialize staticBlock;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top