0

I am trying to wrap a large GUI library called JUCE. I want to generate separate DLLs for separate subsystems and for this I have got separate BOOST_PYTHON_MODULE() statement in visual studio. The projects are separate.

Currently I have 2 projects:

JUCE:

BOOST_PYTHON_MODULE(JUCE)
{
    class_<String>("String", init<char*>())
        .def("toStdString", &String::toStdString);

    def("mainLoop", &mainLoop);
    def("quit", &quit);
}

and COMPONENT:

BOOST_PYTHON_MODULE(COMPONENT)
{   
    class_<PyJuceComponent, boost::noncopyable>("Component")
        .def(init<std::string>())        
        .def("setName", &PyJuceComponent::setName)
        .def("getName", &PyJuceComponent::getName, return_value_policy<return_by_value>())
        .def("getComponentID", &PyJuceComponent::getComponentID, return_value_policy<return_by_value>())
        .def("setOpaque", &PyJuceComponent::setOpaque)
        .def("setVisible", &PyJuceComponent::setVisible)
        .def("addToDesktop", &PyJuceComponent::addToDesktop)
        .def("centreWithSize", &PyJuceComponent::centreWithSize)
        .def("userTriedToCloseWindow", &PyJuceComponent::userTriedToCloseWindow)
        ;

    // enums
    enum_<ComponentPeer::StyleFlags>("StyleFlags")
        .value("windowAppearsOnTaskbar", ComponentPeer::windowAppearsOnTaskbar)
        .value("windowHasTitleBar", ComponentPeer::windowHasTitleBar)
        .value("windowIsResizable", ComponentPeer::windowIsResizable)
        .value("windowHasMinimiseButton", ComponentPeer::windowHasMinimiseButton)
        .value("windowHasMaximiseButton", ComponentPeer::windowHasMaximiseButton)
        .value("windowHasCloseButton", ComponentPeer::windowHasCloseButton)
        .value("windowHasDropShadow", ComponentPeer::windowHasDropShadow)
        ;
}

The String class is the problem. I want to declare the String class in JUCE but I do want to use it with Component as it is the same class.

However this does not seem to work:

str = JUCE.String("hallo")
comp = new COMPONENT.Component()
comp.setName(str)    <---------------------- fails with type mismatch !!

If I add the String class in the COMPONENT module then I can do :

str = COMPONENT.String("hallo")
comp = new COMPONENT.Component()
comp.setName(str) 

But this is non-intuitive. I want to only have JUCE.String() and use it with the other classes, even though they are from different .pyd files (it is the same library and file in the end)

In fact I want to share it as its a very common class used in all parts of the library.

Cross module dependencies in Boost Python

Community
  • 1
  • 1
safe_malloc
  • 824
  • 2
  • 12
  • 29
  • Where you define the `boost::python` wrapper class shouldn't matter so long as they are both imported at runtime . This suggests you actually have a type mismatch somewhere on the C++ side, I.E. you're wrapping a different `String` in Component than in Juic . – aruisdante Oct 18 '14 at 15:14
  • They are the same String class actually. My project may be different but they point to the same files. boost python may somehow be tying the String class to the module name. – safe_malloc Oct 18 '14 at 16:06
  • It would help possibly if you posted the actual error output, and what the C++ signature of `setName` is. Does `getName` also fail when you try and call it? Also, I assume you have the dynamic binary being built as per your linked question yeah? – aruisdante Oct 18 '14 at 16:43
  • Yeah the error is `>>> comp.setName(str) Traceback (most recent call last): File "", line 1, in Boost.Python.ArgumentError: Python argument types in Component.setName(Component, String) did not match C++ signature: setName(class juce::Component {lvalue}, class juce::String)` – safe_malloc Oct 18 '14 at 16:56
  • It seems that each boost python extension module has this type registry which is not shared if each boost module is linked against the static boost library. If boost is built as a dll and then used in both then the type registry is same and types in 1 module can be passed to another if the arguments are of the same c++ class. – safe_malloc Oct 18 '14 at 17:15

0 Answers0