[C++-sig] Re: init function not found [was Re: Problem with different return types. ]

Raoul Gough RaoulGough at yahoo.co.uk
Sat Feb 7 22:13:08 CET 2004


Aashish Chaudhary <aashish at iastate.edu> writes:

> Hi, 
>
> I have compiled boost.python on Linux after unsuccessfull attempt to
> compile it on windows (I found VC7.0 can not compile it as shown the
> status of boost.python compilation for VC7.0 on boost.python web).

I didn't know that VC7.0 support had been dropped - at least, not
deliberately!

>
> Well then I tried to build some basic examples .. and it just worked
> fine ... I got into trouble when I tried to compile a example from
> register_ptr_to_python.hpp

[snip]
> BOOST_PYTHON_MODULE(register_ptr)
> {
>     class_<A, A_Wrapper>("A")
>         .def("f", &A::f, &A_Wrapper::default_f)
>     ;
>     
>     def("New", &New);
>     def("Ok", &Call);
>     def("Fail", &Fail);
>     
>     register_ptr_to_python< shared_ptr<A> >();
> } 
>
> and when in the python file I did this:
>
> from register_ptr import *
>
> it throws me the error :
>
> Traceback (most recent call last):
>   File "usr/src/bp_register_test.py", line 2, in ?
>     from bp_register import *
> ImportError: dynamic module does not define init function (initbp_register)
>
> I am wondering why it would happened ???

This looks very confusing to me, because the error message doesn't
seem to match up to what you "did" in Python. Maybe the problem is
very simple though. If you create a shared object called
register_ptr.so you can import it with "from register_ptr import
...". Python then looks for a Python module or shared object that
matches that name, and in the case of a shared object loads it and
looks for a function called something like initregister_ptr. The
BOOST_PYTHON_MODULE(register_ptr) macro gives you this function,
correctly named.

However, if you want to do "from bp_register import .." (which is what
the error message indicates) you would have to change the name in
BOOST_PYTHON_MODULE as well as the shared object file name.

-- 
Raoul Gough.
export LESS='-X'





More information about the Cplusplus-sig mailing list