1

While trying to overcome the error during importing my shared library hello.so into python (as described in Import Error on boost python hello program) I followed the advice from one of the answers, i.e. trying to compile with following two lines:

g++ -c -fPIC -I boost_1_59_0/ -I /usr/include/python2.7/ hello.cpp -o hello.o
g++ -I boost_1_59_0/ -I /usr/include/python2.7/ -shared -Wl,-soname,hello.so -o hello.so  hello.o -lpython2.7 -lboost_python

The first line works; the second, however, produces the error:

/usr/bin/ld: cannot find -lboost_python
collect2: error: ld returned 1 exit status

After some googling I tried to substitute -lboost_python with -lboost_python-py27 or -lboost_python2.7. Nevertheless, the result is the same.

If I omit the last parameter, I get the error in python:

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

I work under Ubuntu 14.04.3 LTS and use python 2.7.6.

Can someone help me to compile the library correctly?

Community
  • 1
  • 1
Roman
  • 2,225
  • 5
  • 26
  • 55
  • 2
    If you are using the default boost installation I think that you need to have [`libboost-python1.54-dev`](http://packages.ubuntu.com/trusty/i386/libboost-python1.54-dev/filelist) installed. Once you're sure you have that, you'll need to use `-lboost_python-py27` (or probably also `-lboost_python` unless it points to the python3 version). – llonesmiz Oct 21 '15 at 13:20

0 Answers0