[C++-sig] Re: compile errors with embedding example from tutorial

Graeme Lufkin graeme.lufkin at gmail.com
Fri Jul 2 01:12:13 CEST 2004

	Okay, so you're embedding in your extension.  I don't think you need
to call Py_Initialize(), as this should already have been done by the
python executable that you start to import your module.  I don't think
it's wrong to call it multiple times, but should be unnecessary.

On Thu, 1 Jul 2004 22:48:24 +0000 (UTC), Faheem Mitha
<faheem at email.unc.edu> wrote:
> In [1]: import embed
> ---------------------------------------------------------------------------
> ImportError                               Traceback (most recent call
> last)
> /usr/local/src/libboost-python1.31.0/boost-1.31.0/libs/
> python/example/bin/example/embed.so/gcc/debug/shared-linkable-true/<console>
> ImportError: libboost_python.so.1.31.0: cannot open shared object
> file: No such file or directory
> Any idea how to fix this? Debian has /usr/lib/libboost_python.so and
> libboost_python-gcc-mt-1_31.so, where the former is a symbolic link to
> the latter.

   This looks like libbost isn't in your LD_LIBRARY_PATH.  When you
make a Python extension with the 'extension' target in Boost.Build, it
will build a copy of libboost and your extension (look in the bin
directory).  This one is the one that your extension gets linked
against, and so is the one it's looking for when you import the
module.  Since you've got Debian's version of the compiled Boost
libraries installed, it might be better to link against them.  You can
do that with a Jamfile entry similar to:

extension getting_started1-external
	: getting_started1.cpp

Since you're doing embedding in the extension, you probably also need
the embedding flags, so it would look like:

extension embed_in_extend_test
	: embed_in_extend.cpp

variables that are defined by the Boost.Python library Jamfile.

The Jamfile entry for the test I ran (that compiled and ran fine) is:
exe simpletest
Note the different name for the shared library to link against, that's
because I'm using the libraries built by running bjam in the root of
my Boost installation.  They got put in a different directory (which
is also in my LD_LIBRARY_PATH), so I add that to the list of linker
    -- Graeme
    graeme.lufkin at gmail.com

More information about the Cplusplus-sig mailing list