[C++-sig] Re: boost:python:embedding

David Abrahams dave at boost-consulting.com
Tue May 6 18:51:00 CEST 2003

Dirk Gerrits <dirk at gerrits.homeip.net> writes:

> David Abrahams wrote:
>> Dirk Gerrits <dirk at gerrits.homeip.net> writes:
>>>To do this, you can't simply create a module_name.so or
>>>module_name.pyd as you'd do when extending; the BPL wrapper code
>>> must be in the C++ program itself.
>> Loading of plugin extension libraries is disabled? Are you sure?
> No that's not what I meant. You need this only to call the C++ code
> from the embedding program. Say that the C++ program contains the
> functions foo and bar that work on some shared data. (Perhaps they are
> members of the same class.) Now if foo calls some Python code, and
> that Python code needs bar, then obviously bar can't be in a .pyd when
> foo is in a .exe, right?

Ahhm.  Not on Windows, no.  You'd have to link your application and
the .pyd to the Python DLL, instead of linking Python into your
program statically.  On most Unices, extension modules actually get
their Python symbols resolved back into the python executable.

>> I can understand why you'd want to link statically, but it seems to
>> me that dynamic linking should still be possible... no?
> Yes, you can still have *other* C++ code stuffed into extension
> libaries. Sorry for the confusion. This wasn't a bug report. ;)
> [snip]
> [snip]
>>>I have some issues with this though. For starters, the macro name is
>>> much too long for my taste. ;)
>> You could leave out the word "DECLARE".
> OK.
> Yes I looked into it a bit, but I haven't actually changed any
> code. For one, I'm not totally sure how the releasing should be
> done. Py_AtExit() won't suffice

Why, pray tell?

> so I suppose the cleanup function must be exposed to Python to be
> registered with atexit.register() through PyRun_String?

I guess that would be fine.

> BTW, you didn't say anything about whether embedding makes sense
> without defining BOOST_PYTHON_STATIC_MODULE. 

Probably because I don't know ;-)

> My guess is that it doesn't. I'd have to put something about this in
> the tutorial and/or reference so I'd like your thoughts.


Dave Abrahams
Boost Consulting

More information about the Cplusplus-sig mailing list