nergal
January 21, 2018, 9:29pm
1
I finally got Cling to work and link dynamically but I have a newer problem.
Is there a way I can instantiate the cling interpreter without argc
and argv
? I’m embedding Cling to an application through a C++ plugin interface, so there’s no way I can access argc
and argv
. I tried to pass bogus parameters to the cling::Interpreter
constructor but it always crashes the program.
Any way to instantiate cling without args?
wlav
January 22, 2018, 1:15am
2
FWIW, this is ancient code from a prototype that used to work:
/* cling initialization --------------------------------------------------- */
namespace {
cling::Interpreter* gCppyy_Cling;
cling::MetaProcessor* gCppyy_MetaProcessor;
struct Cppyy_InitCling { // TODO: check whether ROOT/meta's TCling is linked in
Cppyy_InitCling() {
std::vector<std::string> cling_args_storage;
cling_args_storage.push_back("cling4cppyy");
// TODO: get this from env
cling_args_storage.push_back("-I/home/wlavrijsen/rootdev/root/etc");
std::vector<const char*> interp_args;
for (std::vector<std::string>::const_iterator iarg = cling_args_storage.begin();
iarg != cling_args_storage.end(); ++iarg)
interp_args.push_back(iarg->c_str());
// TODO: get this from env
const char* llvm_resource_dir = "/home/wlavrijsen/rootdev/root/etc/cling";
gCppyy_Cling = new cling::Interpreter(
interp_args.size(), &(interp_args[0]), llvm_resource_dir);
// fInterpreter->installLazyFunctionCreator(llvmLazyFunctionCreator);
{
// R__LOCKGUARD(gInterpreterMutex);
gCppyy_Cling->AddIncludePath("/home/wlavrijsen/rootdev/root/etc/cling");
gCppyy_Cling->AddIncludePath(".");
}
// don't check whether modules' files exist.
gCppyy_Cling->getCI()->getPreprocessorOpts().DisablePCHValidation = true;
// Use a stream that doesn't close its file descriptor.
static llvm::raw_fd_ostream fMPOuts (STDOUT_FILENO, /* ShouldClose */ false);
gCppyy_MetaProcessor = new cling::MetaProcessor(*gCppyy_Cling, fMPOuts);
gCppyy_Cling->enableDynamicLookup();
}
} _init;
} // unnamed namespace
It was created by stripping down to the bare minimum what ROOT does to initialize cling.
nergal
January 22, 2018, 1:44pm
3
thank you very much wlav!
I’ve successfully loaded up cling with a working value!
cling::Interpreter *g_pInterp;
int main(void)
{
std::vector<std::string> cling_args_storage;
cling_args_storage.push_back("EmbedCling");
// TODO: get this from env
//cling_args_storage.push_back("-I/home/wlavrijsen/rootdev/root/etc");
cling_args_storage.push_back("-I/home/kevin/SourceCodes/C++/Embedding Cling");
std::vector< const char* > interp_args;
{
std::vector< std::string >::const_iterator iarg;
for( iarg = cling_args_storage.begin() ; iarg != cling_args_storage.end() ; ++iarg )
interp_args.push_back(iarg->c_str());
}
// TODO: get this from env
//const char *llvm_resource_dir = "/home/wlavrijsen/rootdev/root/etc/cling";
const char *llvm_resource_dir = "/home/kevin/SourceCodes/C++/Embedding Cling";
g_pInterp = new cling::Interpreter(interp_args.size(), &(interp_args[0]), llvm_resource_dir);
// fInterpreter->installLazyFunctionCreator(llvmLazyFunctionCreator);
{
// R__LOCKGUARD(gInterpreterMutex);
g_pInterp->AddIncludePath("/home/kevin/SourceCodes/C++/Embedding Cling");
g_pInterp->AddIncludePath(".");
}
class cling::Value val;
enum cling::Interpreter::CompilationResult res = g_pInterp->process("int i = 5;", &val);
printf("SMCLING Ext :: Loaded Successfully! -- res -> %i | value == %lli\n", res==cling::Interpreter::kSuccess, val.getLL());
delete g_pInterp;
}
The last remaining issue is building a working path from the plugin extensions folder. I’ll try to figure that one on my own. Thanks again!
system
Closed
February 5, 2018, 1:44pm
4
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.