coding some module in C++ in a project in Python


#1

Hello all,
Some new module needs to be written in c++. Our project is in python.
How do we integrate the new c++ modules into the general python architecture?
And into the panda c++ codebase ?
Any idea ?


#2

Download the panda source code and compile it (very easy). Then, look in panda/src/skel at the two classes in there “BasicSkel” and “TypedSkel.” These are skeleton classes into which you can insert your own data and methods. As a first learning experience, you can just modify one of these classes, make, and see what happens. (Neither class is important - you can modify with impunity.) You can watch to see how your methods get imported into python.

Then, you can make a copy of one of these source files, rename it, and rename the class. Insert the new source file into the skel directory, and add an include-directive to skel_composite1.cxx. Presto, new class.

Finally, you can learn how to make your own makefile. When makepanda compiles the skel directory, look at the commands it issues. You’ll see it doing these steps:

  • Generate libskel_igate.cxx (python wrappers)
  • Generate libskel_module.cxx (more python wrappers)
  • Compile skel_composite.cxx and the two generated files
  • Link it all together into libpandaskel.dll

Note the exact commands that makepanda issues. Create your own makefile that duplicates these steps. Then, rename everything from “skel” to whatever you want. Presto, you now have your own DLL that you can load into a panda program. Put it in the panda BIN directory. To load it, use

from libpandawhatever import …


#3

PS. I intend to include a sample of this process into the panda distro sometime soon. But around here, “soon” means “in the next 12 months.”


#4

Thank you for your explication. that will help a lot.