[C++-sig] Using C++ classes exposed by other modules

Jim Bosch talljimbo at gmail.com
Thu Oct 14 21:01:15 CEST 2010


On 10/14/2010 10:17 AM, Bryant Gipson wrote:
> Hi All,
>
> Maybe a simple question, maybe not:
>
> I have a binary-only module which was automatically generated by Py++
> and its associated pre-compiled C++ libraries.
>
> There's a basic C++ type "A" which was exposed along with plenty of
> support functions in the associated C++ library which operate on it in
> both C++ and Python.
>
> i.e.
>
> python:
> a = mod.A();
> mod.helpfulFunction(a);
>  >>Some helpful output.
>
> My problem is now I want to write a module which operates on the C++
> class A.
>
> C++:
>
> void mySlightlyHelpfulFunction(cppmodule::A &a)
> {
> ...
> }
>
> BOOST_PYTHON_MODULE(myModule)
> {
> def("mySlightlyHelpfulFunction",mySlightlyHelpfulFunction);
> }
>
> Python:
> a = mod.A()
> myModule.mySlightlyHelpfulFunction(a)
> myModule.mySlightlyHelpfulFunction(A)
> did not match C++ signature:
> mySlightlyHelpfulFunction(mod::A {lvalue})
>
> I've also tried this with Py++ with the same results.
> Thus far it appears that no converter has been globally registered by
> the module mod.
>
> Any help would be hugely appreciated.
>
> I apologise if this is a trivial question, I'm still new to hybrid
> C++/python.
>

This *should* work without anything extra, and generally does in a lot 
of my own code.

All I can think of is that your two modules somehow are getting 
different copies of the Boost.Python registry (maybe that happens with 
static linking to the Boost Python library - if that's even possible?)

What platform/compiler are you using?


Jim Bosch


More information about the Cplusplus-sig mailing list