Cppyy - how to dynamically retrieve objects found in header?

After successful cppyy.c_include(), how can one dynamically retrieve the declarations and macros found in the header ?

I understand that normally one simply manually establishes linkage via: “foo = cppyy.gbl.foo” where foo then gets looked up internally on the C++ side. Where is this name lookup done done so that I can use it directly ?

I need to be able to pull sets of such into the local python scope without specifying each individually. I would greatly appreciate it if someone could point me in the right direction.


ROOT Version: cling 6.15/02 without ROOT
Platform: Linux/Ubuntu
Compiler: cling / g++ / clang

Welcome, @phdye !
As you can see from dir(cppyy.gbl.std) we load these things lazily: we look foo up as cppyy.gbl.foo is requested.

Usually cppyy uses (a core part of) ROOT behind the scenes - I don’t know how accessible that is. If you can access it you can query it for known classes, functions, templates etc: it can build “authoritative” lists when told. E.g. through gClassTable: cppyy.gbl.gClassTable.Print(), or TGlobals see cppyy.gbl.gROOT.GetListOfGlobals().Print(). If you provide more details I might be able to help better.


Above, Philip shows the use of c_include(), meaning he’s using modern cppyy, not the old PyCintex.py that lives on as cppyy.py under bindings/pyroot (and which has no c_include). If you were to try dir() in modern cppyy, you’d be greeted with a screen full of stuff. Of course, bindings are still created lazily (dir() simply returns a list of strings).

What does “directly” mean in this context? Ie. what are you missing from dir()? For sure, macros are not in there, though. I’ve been meaning to add those b/c of things like MPI, but it hasn’t been a priority.

However, if Axel’s answer is on the right track, then you can get more examples here:
and in particular the function Cppyy::GetAllCppNames() (which is used in dir()).

1 Like

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