[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Linkage of SWIG/PYthon bindings against libpython on Solaris with gcc

From: Daniel Rall <dlr_at_collab.net>
Date: 2005-12-21 02:38:12 CET

I've been trying to compile Subversion 1.3.0-rc4 on Solaris 10 with
GCC 3.4.2. While compiling the SWIG/Python bindings via 'make
swig-py', I get the following error from ld when libtool attempts to
link libsvn_swig_py:

--- snip ---
...
strncat 0xc84 /opt/sfw/lib/python2.2/config/libpython2.2.a(getpath.o)
ld: fatal: relocations remain against allocatable but non-writable sections
collect2: ld returned 1 exit status
make: Fatal error: Command failed for target `subversion/bindings/swig/python/libsvn_swig_py/libsvn_swig_py-1.la'
--- snip ---

A pile of lines like the first shown (with symbol name, offset, and
library) are spewed before we get to the actual linker failure. The
failure is triggered by an attempted linkage with Python's static
library (libpython2.X.a, where X is your installed version). Removal
of this linkage from the Makefile restores the state of the bindings
in Subversion 1.2.3, and results in a successful build of the Python
bindings.

Something in the neighborhood of the following commit introduced the
linkage to the Python library:

------------------------------------------------------------------------
r10450 | maxb | 2004-07-31 15:11:08 -0700 (Sat, 31 Jul 2004) | 9 lines

Explicitly link the python bindings against libpython.

* Makefile.in: New substitution variable, SWIG_PY_LIBS.
* build.conf: Add SWIG_PY_LIBS to the libsvn_swig_py link.
* build/ac-macros/swig.m4: Set and substitute SWIG_PY_LIBS.
* build/get-py-info.py: New --libs option to provide SWIG_PY_LIBS.
  Teach how to escape OS X -framework options so libtool doesn't eat them.
  Teach how to add extra library arguments on Cygwin, like distutils does.

------------------------------------------------------------------------

The mechanics of the change involve swig.m4 calling get-py-info.py for
some compilation and linking options:

    AC_CACHE_CHECK([for linking Python libraries], [ac_cv_python_libs],[
      ac_cv_python_libs="`$PYTHON ${abs_srcdir}/build/get-py-info.py --libs`"
    ])
    SWIG_PY_LIBS="$ac_cv_python_libs"

Here's what that looks like on the command-line, the output of which I
remove from the Makefile for a successful build:

[dlr@sc-soldev4:subversion-1.3.0-rc4]$ python ./build/get-py-info.py --libs
-L/opt/sfw/lib/python2.2/config -lpython2.2

What's the need behind the explicit linkage with of the bindings with
libpython?

Google hits for this linker error suggested using -fPIC (already in
use) and/or -G (not helpful). They also suggested building against a
libpython shared library, which I've tested and found to work.
However, a shared library is not available for Python 2.2.3 (though
Garrett came up with a patch to Python 2.2.3's build system that would
let us create a .so), which is the version of Python my application
code has been qualified and packaged for.

Understandably, I would prefer to be able to build Subversion's
bindings against Python 2.2.3, rather than upgrade Python. Thoughts?

--
Daniel Rall

  • application/pgp-signature attachment: stored
Received on Sun Dec 25 05:37:53 2005

This is an archived mail posted to the Subversion Dev mailing list.