I’m trying to do the following setup:
cling::Interpreter object and pass the
*.pch file to it.
- Load the C++ file with few declarations, and function definition.
- Run the function.
- Reset the state to the state 1.
So far I’ve been trying this:
cling::Interpreter interp("-include-pch" /* pseudo code, passing pch */);
cling::Interpreter::Transaction pTx = nullptr;
interp.loadFile("my_cppfile", false, &pTx);
However, sometimes it seems that the entire PCH gets unloaded (so the “my_cppfile.cpp” fails to compile even). Am I doing something obviously wrong? I’ve tried to search for examples, but I couldn’t find many. I also tried to have two transactions, one in loadFile, one in process, to pass the same one, or to do
unload(2), but I had no lock.
Unloading is the toughest operation for cling - it’s something clang really doesn’t do, ever, and we know of issues with it.
As an alternative you could consider starting a child interpreter. That mostly depends on the complexity of the code in the PCH: if clang implemented AST copying / injection for it you can set up a parent interpreter with the PCH, and then move any subsequent operations into a short-lived child interpreter. See the constructor here: cling: cling::Interpreter Class Reference
(And we really need to get our CI to update those doxygen pages…)
Thank you, Axel, I will try this and report back.
Hi Axel, just to report back - it seems that for the particular PCH, clang didn’t do whatever is supposed to do, so if I create the child interpreter, none of the symbols from PCH are visible (unless I pass the PCH again via -include-pch, but that causes a significant startup hit).
Thank you anyway for the software, it’s a pleasure tinkering with it.
Hmm that’s surprising, I did not expect complete failure with the child interpreter…
OK well, so we need to figure out what fails in the unloading case. Can you provide us with a minimal reproducer of
m_cppfile that shows this issue of unloading and reloading?
Thanks for your kind words!
I’ll try to do that over the weekend, thanks!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.