Boost::Python Not Finding C++ Class in OSX
Question: I'm porting an Application from Linux to OS X and the Boost::Python
integration is failing at run time.

I'm exposing my C++ classes like so:

    
    
    using namespace scarlet;
    
    BOOST_PYTHON_MODULE(libscarlet) {
        using namespace boost::python;
    
        class_<VideoEngine, boost::noncopyable>("VideoEngine", no_init)
            .def("play", &VideoEngine::play)
            .def("pause", &VideoEngine::pause)
            .def("isPaused", &VideoEngine::isPaused)
            [...]
        ;
    }
    

I'm importing the library like so:

    
    
    try {
        boost::python::import("libscarlet");
    } catch (boost::python::error_already_set & e) {
        PyErr_Print();
    }
    

Then I'm inject an instance into the global Python namespace like so:

    
    
    void VideoEngine::init() {
        [...]
        try {
            auto main_module = boost::python::import("__main__");
            auto main_namespace = main_module.attr("__dict__");
            main_namespace["engine"] = boost::python::object(boost::python::ptr(this));
        } catch (boost::python::error_already_set & e) {
            PyErr_Print();
        }
        [...]
    }
    

It works great in Linux but in OS X an exception is thrown and `PyErr_Print()`
returns `TypeError: No Python class registered for C++ class
scarlet::VideoEngine`.

As far as I can tell the module works without issue when imported via the
Python interpreter. It is difficult to test since it designed to be injected
as a pre-constructed instance but the class and functions are present as shown
below:

    
    
    $ python
    Python 2.7.5 (default, Mar  9 2014, 22:15:05) 
    [GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> import libscarlet
    >>> libscarlet.VideoEngine
    <class 'libscarlet.VideoEngine'>
    >>> libscarlet.VideoEngine.play
    <unbound method VideoEngine.play>
    

Any ideas as to where the incompatibility lies?

**Edit:** ~~I'm starting to think it might be related to multithreading since
my OS X implementation uses a different threading structure, although all of
the calls detailed here happen in the same thread. Could that be the cause of
such an issue?~~ Probably not the issue since it doesn't work in MS Windows in
single-threaded mode.


Answer: I have solved this now.

It was caused entirely by Boost::Python being statically compiled and once I
recompiled it as a shared library the problem went away entirely, on all
platforms.

The lesson: don't compile boost statically. I'm pretty sure there are warnings
against it and they should be heeded.

