Boost logo

Boost Users :

Subject: Re: [Boost-users] unable to load the module from simple example
From: Vladimir Prus (vladimir_at_[hidden])
Date: 2010-11-09 03:36:12


Cuma Tyszkiewicz wrote:

> Hello
>
> I have followed the simple example from the python boost wiki page:
>
> my source file py_moddef.cc:
> ___________________________________________
> #include <string>
> #include <boost/python.hpp>
>
> char const* greet()
> {
> return "hello, world";
> }
>
> BOOST_PYTHON_MODULE(hello_ext)
> {
> using namespace boost::python;
> def("greet", greet);
> }
> ____________________________________________
>
> In the next step I have built the shared library
>
> 1. g++ -c -fpic -I/usr/include/python2.6/ py_moddef.cc
> 2. ld -G py_moddef.o -o libpy_moddef.so

I recommend that you never invoke "ld" directly. That's dangerous.

>
> The libpy_moddef.so file I have copied to the directory which next was included
> to PYTHONPATH
>>>> import sys
>>>> sys.path.append("the_path")
>
> I am not able to import the module "hello_ext" defined in py_moddef.cc, but I
> am able to import each other python module from this path, so something wrong
> is with the shared library.
>
>>>> import hello_ext
> ImportError: No module named hello_ext
>
> Please explain to me what is wrong. I will be gratefull for any help.

if libpy_modedef.so uses Boost.Python, without linking to Boost.Python library,
things won't work. You have to link to that library, and make sure it's found
by dynamic linker.

- Volodya


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net