[C++-sig] Py++/boost::python: How to correctly wrap libraries (DLLs) with dependencies on each other.

mtn mtn at xcm.ch
Mon Jan 11 17:15:16 CET 2010


Hi all,

I try to embed a Python interpreter into my project using
Py++/boost::python.

I have a problem wrapping different libraries for which i own the source and
which I compile to DLL/*.so files . The libraries have dependencies on each
other but do not necessarily have to be used together.


An abstract example:

The interpreter is in a library on which all other libraries depend and
where they register themselves using init functions generated by
py++/boost::python.
Let's say I have a base library B.
Additionally a library E extending library B.

lib B:
class __exported_to_python__ Base {
  void __exported_to_pytthon__  foo(){...}
}

lib E -> depends B:
class __exported_to_python__ Extended : public B
{
  void __exported_to_python__  boo(){...}
}

It makes sense to also use B alone, therefore I would like to build a Python
wrapper for each library directly into the DLL.

Now I register my init function generate by Py++/boost::python to the
interpreter instance using `PyImport_AppendInittab`.

The thing, that I cannot generate a proper inheritance relation between the
class `Extended` and `Base` without telling Py++ to wrap both classes. But
then I have wrapped `Base` twice. Once in B and once in E.
And when boost::python tries to register some transfer functions based on
the C++ type (RTTI) it fails, as it has already been registered (because
init_B was called).

If I simply delete the duplicated classes by hand from the wrapper of
library `E` it works.
But one has to ensure that first `B` is imported to Python (`import B`) and
afterwards `E` (`import E`) otherwise boost::python does not have `Base`
registered on which `Extended` depends.


I hope I made myself clear enough now :-)
So has anybody solved this problem before me?
I did not find a source which would explain how to solve this issue with
Py++ and boost::python.

Thanks for all the fish!

solong

Martin










-- 
View this message in context: http://old.nabble.com/Py%2B%2B-boost%3A%3Apython%3A-How-to-correctly-wrap-libraries-%28DLLs%29-with-dependencies-on-each-other.-tp27112969p27112969.html
Sent from the Python - c++-sig mailing list archive at Nabble.com.



More information about the Cplusplus-sig mailing list