문제

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?

도움이 되었습니까?

해결책

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;
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top