how to link project with a specified libpython in static? (using boost.Python)

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

how to link project with a specified libpython in static? (using boost.Python)

jeanluc chasseriau
Hi,

We would need help to solve a link problem on our project.
We are developing a project using boost, boost.Python, and bjam, but we would like to embedded our own python library in static form.

I'm currently developing on darwin (macosx 10.5).

Python sources have been integrated in our project (/.../project_path/libs/Python), and we building the static library thanks to the Makefile (resulting in: /.../project_path/libs/Python/libpython2.5.a).

Our project is using bjam, and in the Jamroot we define:
...
using python  : # 2.5
       : /.../project_path/libs/Python/python # cmd-or-prefix
       : [ getPythonIncludePaths ] # includes (return: /.../project_path/libs/Python/Include ...)        
       : [ getPythonLibPath ] # libraries (return: /.../project_path/libs/Python)
       : [ getPythonConditions ] #conditions (return: <variant>debug <python-debugging>on <link>static)
       ;
...

The project Jamfile is:
...
exe testscript : [ glob *.cpp ]
      /otherlib//otherlib
      /boost/python//boost_python/<link>static
      /python//python/<link>static
      ;  

The problem appear during the link stage, the generated g++ command looks like:
g++ -L"/.../project_path/libs/Python" -I"/.../project_path/libs/Python/Include" ... -o testscript "/.../project_path/libs/sys/libotherlib.a" "/.../project_path/libs/boost/libs/python/.../boost_python.a"  main.o ... -lpython2.5 -g

This failed due to unresolved symbols with python library:
Undefined symbols:
  "__Py_NegativeRefcount", referenced from:
      boost::python::detail::decref_guard::~decref_guard()in main.o
...

Manually, I've tried:
a) replace "-lpython2.5" by /.../project_path/libs/Python/libpython2.5.a : this is working just fine - the exe is linked and everything work

b) rename the system python library "/usr/lib/libpython2.5.dylib" (so g++ cannot find it at link stage) : this is also working fine.

So, by using -lpython2.5, we encourage g++ to find libraries in its standard paths, which I would like to avoid since we would like to statically build our own libpython.

Is there any nice method to tell bjam / boost.python to use our own python library (in static)?

A good way would be that bjam use the full path to the static version (project_path/libs/Python/libpython2.5.a) of it when linking exe to it, is there a way to do so?

Thanks in advance for your help!

Best regards,

jeanluc