Instantiate Cling without args?

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?

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;

        // TODO: get this from env

        std::vector<const char*> interp_args;
        for (std::vector<std::string>::const_iterator iarg = cling_args_storage.begin();
                iarg != cling_args_storage.end(); ++iarg)

        // 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);

        // 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);

} _init;

} // unnamed namespace

It was created by stripping down to the bare minimum what ROOT does to initialize cling.

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;

	// TODO: get this from env
	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 )

	// 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");
	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!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.