Suppose I have two boost python modules that are defined as follows. Module A:
class SomeClass {
public:
SomeClass() {}
~SomeClass() {}
};
BOOST_PYTHON_MODULE(A)
{
class_<SomeClass>("SomeClass");
}
And module B:
class AnotherClass {
public:
AnotherClass() {}
~AnotherClass() {}
void func(SomeClass& sp) {}
};
BOOST_PYTHON_MODULE(B)
{ class_<AnotherClass>("AnotherClass")
.def("func", &AnotherClass::func)
;
}
Module B has a dependency on module A (i.e. it uses SomeClass from module A). Now, I execute the following python script:
import A
import B
obj1 = A.SomeClass()
obj2 = B.AnotherClass()
obj2.func(obj1)
I get the following error:
Traceback (most recent call last):
File "C:\bladiebla\script.py", line 8, in <module>
obj2.func(obj1)
ArgumentError: Python argument types in
AnotherClass.func(AnotherClass, SomeClass)
did not match C++ signature:
func(class AnotherClass {lvalue}, class SomeClass)
It seems that Python does not automatically translate classes between modules. Does anyone have an idea how to solve this?
Based on your latest response and updated error message in your question, I think the problem might be because your
BOOST_PYTHON_MODULEusage might be incorrect (based on what I've seen in other examples of using it). Try something like this and see if it helps:Module A:
And module B:
Note the insertion of a "
boost::python::" prefix onto theclass_<...>statement in each of the twoBOOST_PYTHON_MODULEdeclarations.