I have wondered about this on and off but I never really got a definite answer. Is it possible within the boost.python framework to link against another boost.python module.
For example I have exported class A within boost_python_module(libA) and function B(A a) within boost_python_module(libB). Is it possible to specify in libB to link to A of libA.
The other way of looking at this problem would be that right now I have to generate all my bindings in one shot within one module. Is it possible to generate bindings incrementally over several boost_python_module.
The Boost.Python way to handle what you are asking for is to divide your package in compilation units as explained in the tutorial and later do a merge in a main compilation unit that actually declares the modules.
You cannot link independent modules in Boost.Python because they declare specific Python entry points that are executed by Python when you load your module. For example, if the binary module name is mod.so
, the Python interpreter will look for a function called init_mod
(that is what BOOST_PYTHON_MODULE(mod)
declares) and execute the code of that function. Within the code of that function, it expects to find Python C-API declarations of objects (instances, classes, etc).
If you link, for example, the mod.so
binary to another module binary (say, foo.so
), when Python loads mod.so
, it would only find and execute init_mod
and will ignore init_foo
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With