[C++-sig] Problem with importing shared library into Python

Edgardo C. edxxgardo at gmail.com
Fri Nov 25 16:06:09 CET 2011


We have this situation(remember that the source code is from the book API
C++ design www.apibook.com):

Source code:

- phonebook.h
- phonebook.cpp
- phonebook_wrap.cpp

Boost is download, compiled and installed into:
- /Desktop/boost_1_48_0/compilation/

which means that /include and /lib are the subfolders of this with all the
headers and libraries into it.

Now:

g++ -c
phonebook.cpp
(compiles only phonebook.cpp, without error)
g++ -c phonebook_wrap.cpp -I<boost_includes> -I<python_include>  (compiles
the wrapper against the /include subfolder mentioned before and the
python2.7 headers in /usr/...)
g++ -shared -o phonebook.so phonebook.o phonebook_wrap.o -lboost_python
-lpython (links the objects agains the /lib subfolder mentioned before and
and python2.7 libraries in /usr/...)

After this I get the phonebook.so shared library, but when I try to import
it in python I get the error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: ./phonebook.so: undefined symbol:
_ZN5boost6python6detail11init_moduleEPKcPFvvE


Hope this can help better to understand (maybe) what is going on. Again, I
follow the same procedure after installing the precompiled packages from
Ubuntu using synaptic, and the same error. Hope that somebody can help.




















2011/11/25 Jim Bosch <talljimbo at gmail.com>

> On 11/25/2011 06:54 AM, Edgardo C. wrote:
>
>> Hello everybody,
>>
>> I am having problems with importing a .so shared library I just compiled
>> following the example giving in the book:
>> API Design for C++ : www.apibook.com <http://www.apibook.com> (Chapter
>> 11)
>>
>>
>> I downloaded the Boost library and I compiled it (fullw) into a
>> subdirectory called /compilation, where I get the /include and /lib
>> directories. No error during the compilation (Ubuntu 11.10).
>> Then I downloaded the code from the book examples and I compiled it
>> without errors and I get the phonebook.so in the same directory as where
>> I launch python interpreter, but the import in python trigger this error:
>>
>>
>> ImportError: /home/pablo/phonebook/**phonebook.so: undefined symbol:
>> _ZN5boost6python6detail11init_**moduleEPKcPFvvE
>>
>> what I think is because python does not find the library.
>>
>> I try to play around with the LD_LIBRARY_PATH variable, ldconfig, I
>> copied the phonebook.so library into /usr/lib and /usr/local/lib, and
>> nothing ... I get the same error.
>>
>> Can anybody explain me what is the problem? thanks a lot in advance,
>>
>>
> I think you just need to link your library against the boost_python
> library, and make sure that's also somewhere on your dynamic library path.
>  With gcc, that means adding a "-lboost_python" to the command line options.
>
> Jim
>
> ______________________________**_________________
> Cplusplus-sig mailing list
> Cplusplus-sig at python.org
> http://mail.python.org/**mailman/listinfo/cplusplus-sig<http://mail.python.org/mailman/listinfo/cplusplus-sig>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20111125/97c86c3d/attachment-0001.html>


More information about the Cplusplus-sig mailing list