Dictionary generation including PyROOT C++ Objects

Hi there,

I’m trying to generate a dictionary for a class that uses some PyROOT C++ objects with a “simple” LinkDef file. Here’s the LinkDef:

#ifndef ROOTUTILS_LINKDEF_H
#define ROOTUTILS_LINKDEF_H

#include "RootUtils/PyROOTTypePatch.h"

#ifdef __CINT__

#pragma link off all globals;
#pragma link off all classes;
#pragma link off all functions;
#pragma link C++ nestedclasses;

#pragma link C++ namespace RootUtils;
#pragma link C++ class RootUtils::PyROOTTypePatch+;

#endif
#endif

And the header file I’m using:

#ifndef ROOTUTILS_PYROOTTYPEPATCH_H
#define ROOTUTILS_PYROOTTYPEPATCH_H

#ifdef _POSIX_C_SOURCE
# undef _POSIX_C_SOURCE
#endif
#include "Python.h"

namespace RootUtils {

class PyROOTTypePatch
{
public:
  static void initialize (PyObject* pyroottype);
};

} // namespace RootUtils

#endif // not ROOTUTILS_PYROOTTYPEPATCH_H

When I run dictionary generation, I get:

Seems as though the typedefs in python’s object.h aren’t understood by CINT? But it’s not clear to me how much of this I need to include (tried the obvious but apparently wrong inclusion of Python.h and object.h with pragma link lines for the typedefs it complains about, but to no avail). I’m sure I’m missing something simple here… any help would be much appreciated!

Thanks,
Zach

Zach,

you really only need PyObject* to be known to expose that function. For that, these two lines will do, instead of Python.h:struct _object; typedef _object PyObject;
Cheers,
Wim

Hi Wim,

Adding those two lines to the header file and removing the include of Python.h worked like a charm, thanks!

Best,
Zach