Boost logo

Boost :

From: David Abrahams (abrahams_at_[hidden])
Date: 2001-03-21 11:45:31

> -----Original Message-----
> From: Karl Bellve [mailto:Karl.Bellve_at_[hidden]]

> I have installed Python and I have been able to statically link it into
> my application. I am now using Boost to try use a C++ class from
> Python.
> It appears that Boost really wants me to make a DLL that python then
> loads.

That's the usual way that extension modules are built.

> What if I want to statically link my C++ class to my application
> and linked to python? How do I notify Python of the Class and some of
> its methods?

Are you embedding the Python interpreter in your application? I am not an
expert on this, but I believe you still need to make a Python module, and
there is a way to cause a statically-linked python module to be loaded. You
might take a look at the Python sources to see how it loads some of its
compiled-in modules (e.g. builtins...), or ask a question on, say

> I want the class to be loaded by my application, which
> needs it, then export an instance of that class to python. Then the user
> will then be able to run python scripts through my application, not
> through an external python shell.
> I have listed a few of the class methods in BOOST_PYTHON_MODULE_INIT but
> I am not clear on where to go from there.

BOOST_PYTHON_MODULE_INIT is a macro which is specially-designed for building
DLLs/shared objects. Its definition is:

  #define BOOST_PYTHON_MODULE_INIT(name) extern "C" __declspec(dllexport)
void init##name()

So it just ends up defining a void function called init<module-name>(). You
probably don't want to use it because of the dllexport stuff, but some
similar function definition makes sense. Now you just have to figure out how
to get Python to load a statically-linked module by executing your module
initialization function.

If you find an answer and would like to make a tiny demo program for the
boost.python distribution, it would be very much appreciated...


Boost list run by bdawes at, gregod at, cpdaniel at, john at