[ python-Bugs-1600860 ] --enable-shared links extensions to libpython statically

SourceForge.net noreply at sourceforge.net
Sat Nov 25 14:10:00 CET 2006


Bugs item #1600860, was opened at 2006-11-22 00:29
Message generated for change (Comment added) made by gustavo
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1600860&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Distutils
Group: None
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Marien Zwart (marienz)
Assigned to: Nobody/Anonymous (nobody)
Summary: --enable-shared links extensions to libpython statically

Initial Comment:
python 2.5 tries to link extension modules to libpython2.5 if python is compiled with --enable-shared (patch #1429775, bug #83279, svn r45232). To do this it adds -lpython2.5 and -L$PREFIX/lib/python2.5/config to the link command line. -lpython2.5 is fine, however the "config" directory it adds contains a static libpython2.5.a library. The libpython2.5.so I think it should be linking to is in $PREFIX/lib. The result is even a trivial extension pulls in (nearly) all of that library, so you get an extension that is over a megabyte in size where older pythons produce one of a few kilobytes.

There is a comment on the referenced bug saying

"""
You can probably rely on libpythonxy.so ending up in
$(DESTDIR)$(LIBDIR)/$(INSTSONAME), whose values you can
retrieve from the installed Makefile (i.e. through
distutils.config).
"""

so I think the patch that got applied does not do what was intended.

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

Comment By: Gustavo J. A. M. Carneiro (gustavo)
Date: 2006-11-25 13:10

Message:
Logged In: YES 
user_id=908
Originator: NO

*sigh* why doesn't SF let me attach patches? :(

You can find a patch to fix this here:
http://www.gnome.org/~gjc/linux-shlib.diff


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

Comment By: Gustavo J. A. M. Carneiro (gustavo)
Date: 2006-11-23 20:47

Message:
Logged In: YES 
user_id=908
Originator: NO

Hmm.. I think I wrongfully assumed $prefix/lib/pythonX.Y/config contained
a shared python library in addition to the static one.  It seems that was
an Ubuntu specific thing :|

I'll take a good look and fix this within a couple of days...

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

Comment By: Marien Zwart (marienz)
Date: 2006-11-22 13:02

Message:
Logged In: YES 
user_id=857292
Originator: YES

I can reproduce this by using either gentoo's python 2.5 or one I
installed temporarily with ./configure --enable-shared --prefix
$HOME/tmp/pytem, using a trivial distutils extension (I used
http://dev.gentooexperimental.org/~marienz/ext.c and
http://dev.gentooexperimental.org/~marienz/setup.py for testing). The
relevant command that is run is:

gcc -pthread -shared build/temp.linux-i686-2.5/ext.o
-L/home/marienz/tmp/pytem/lib/python2.5/config -lpython2.5 -o
build/lib.linux-i686-2.5/ext.so

for the manually-configured python and something similar for gentoo's
python. The code doing the adding was added by r45232 in svn. From the
diff (svn di -r45231:45232
http://svn.python.org/projects/python/trunk/Lib/distutils/command/build_ext.py)
with some extra context added:

-        if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
+        if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos'
or \
+               (sys.platform.startswith('linux') and
+                sysconfig.get_config_var('Py_ENABLE_SHARED')):
             if string.find(sys.executable, sys.exec_prefix) != -1:
                 # building third party extensions
                 self.library_dirs.append(os.path.join(sys.prefix, "lib",
                                                      "python" +
get_python_version(),
                                                      "config"))

(that is around line 188 of Lib/distutils/command/build_ext.py)

sys.platform on this host is linux2 and as far as I can tell
Py_ENABLE_SHARED is true if --enable-shared is passed to configure.

If you need any more information please ask.

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

Comment By: Martin v. Löwis (loewis)
Date: 2006-11-22 07:09

Message:
Logged In: YES 
user_id=21627
Originator: NO

I can't reproduce the problem. Why do you think
-L$PREFIX/lib/python2.5/config is added to the link command line? AFAICT,
it never is.

What operating system are you using?

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

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1600860&group_id=5470


More information about the Python-bugs-list mailing list