Skip to content

Commit 10acfd0

Browse files
committed
Patch #1429775: Link Python modules to libpython on linux if
--enable-shared. Fixes #832799.
1 parent b04dee9 commit 10acfd0

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

Lib/distutils/command/build_ext.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,9 @@ def finalize_options (self):
185185

186186
# for extensions under Cygwin and AtheOS Python's library directory must be
187187
# appended to library_dirs
188-
if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos':
188+
if sys.platform[:6] == 'cygwin' or sys.platform[:6] == 'atheos' or \
189+
(sys.platform.startswith('linux') and
190+
sysconfig.get_config_var('Py_ENABLE_SHARED')):
189191
if string.find(sys.executable, sys.exec_prefix) != -1:
190192
# building third party extensions
191193
self.library_dirs.append(os.path.join(sys.prefix, "lib",
@@ -688,6 +690,13 @@ def get_libraries (self, ext):
688690
# extensions, it is a reference to the original list
689691
return ext.libraries + [pythonlib, "m"] + extra
690692
else:
691-
return ext.libraries
693+
from distutils import sysconfig
694+
if sysconfig.get_config_var('Py_ENABLE_SHARED'):
695+
template = "python%d.%d"
696+
pythonlib = (template %
697+
(sys.hexversion >> 24, (sys.hexversion >> 16) & 0xff))
698+
return ext.libraries + [pythonlib]
699+
else:
700+
return ext.libraries
692701

693702
# class build_ext

Lib/distutils/sysconfig.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ def parse_config_h(fp, g=None):
213213
"""
214214
if g is None:
215215
g = {}
216-
define_rx = re.compile("#define ([A-Z][A-Z0-9_]+) (.*)\n")
217-
undef_rx = re.compile("/[*] #undef ([A-Z][A-Z0-9_]+) [*]/\n")
216+
define_rx = re.compile("#define ([A-Z][A-Za-z0-9_]+) (.*)\n")
217+
undef_rx = re.compile("/[*] #undef ([A-Z][A-Za-z0-9_]+) [*]/\n")
218218
#
219219
while 1:
220220
line = fp.readline()
@@ -351,6 +351,17 @@ def _init_posix():
351351

352352
raise DistutilsPlatformError(my_msg)
353353

354+
# load the installed pyconfig.h:
355+
try:
356+
filename = get_config_h_filename()
357+
parse_config_h(file(filename), g)
358+
except IOError, msg:
359+
my_msg = "invalid Python installation: unable to open %s" % filename
360+
if hasattr(msg, "strerror"):
361+
my_msg = my_msg + " (%s)" % msg.strerror
362+
363+
raise DistutilsPlatformError(my_msg)
364+
354365
# On MacOSX we need to check the setting of the environment variable
355366
# MACOSX_DEPLOYMENT_TARGET: configure bases some choices on it so
356367
# it needs to be compatible.

Misc/NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Library
3333
Build
3434
-----
3535

36+
- Patch #1429775: Link extension modules with the shared libpython.
37+
3638
C API
3739
-----
3840

0 commit comments

Comments
 (0)