summaryrefslogtreecommitdiffstats
path: root/Lib/distutils/command
diff options
context:
space:
mode:
authorE. M. Bray <erik.bray@lri.fr>2019-05-24 15:33:47 (GMT)
committerVictor Stinner <vstinner@redhat.com>2019-05-24 15:33:47 (GMT)
commitc994c8fc196a167c57c8850e8abdee170d366eec (patch)
tree91b6151165264da2965ef85baaa0cbb420ed67f5 /Lib/distutils/command
parent438a12dd9d85f463c0bb7bf1505cd87b98b98170 (diff)
downloadcpython-c994c8fc196a167c57c8850e8abdee170d366eec.zip
cpython-c994c8fc196a167c57c8850e8abdee170d366eec.tar.gz
cpython-c994c8fc196a167c57c8850e8abdee170d366eec.tar.bz2
bpo-21536: On Cygwin, C extensions must be linked with libpython (GH-13549)
It is also possible to link against a library or executable with a statically linked libpython, but not both with the same DLL. In fact building a statically linked python is currently broken on Cygwin for other (related) reasons. The same problem applies to other POSIX-like layers over Windows (MinGW, MSYS) but Python's build system does not seem to attempt to support those platforms at the moment.
Diffstat (limited to 'Lib/distutils/command')
-rw-r--r--Lib/distutils/command/build_ext.py36
1 files changed, 24 insertions, 12 deletions
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index c3b9602..2d7cdf0 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -714,20 +714,32 @@ class build_ext(Command):
# don't extend ext.libraries, it may be shared with other
# extensions, it is a reference to the original list
return ext.libraries + [pythonlib]
- # On Android only the main executable and LD_PRELOADs are considered
- # to be RTLD_GLOBAL, all the dependencies of the main executable
- # remain RTLD_LOCAL and so the shared libraries must be linked with
- # libpython when python is built with a shared python library (issue
- # bpo-21536).
else:
+ # On Android only the main executable and LD_PRELOADs are considered
+ # to be RTLD_GLOBAL, all the dependencies of the main executable
+ # remain RTLD_LOCAL and so the shared libraries must be linked with
+ # libpython when python is built with a shared python library (issue
+ # bpo-21536).
+ # On Cygwin (and if required, other POSIX-like platforms based on
+ # Windows like MinGW) it is simply necessary that all symbols in
+ # shared libraries are resolved at link time.
from distutils.sysconfig import get_config_var
+ link_libpython = False
if get_config_var('Py_ENABLE_SHARED'):
- # Either a native build on an Android device or the
- # cross-compilation of Python.
- if (hasattr(sys, 'getandroidapilevel') or
- ('_PYTHON_HOST_PLATFORM' in os.environ and
- get_config_var('ANDROID_API_LEVEL') != 0)):
- ldversion = get_config_var('LDVERSION')
- return ext.libraries + ['python' + ldversion]
+ # A native build on an Android device or on Cygwin
+ if hasattr(sys, 'getandroidapilevel'):
+ link_libpython = True
+ elif sys.platform == 'cygwin':
+ link_libpython = True
+ elif '_PYTHON_HOST_PLATFORM' in os.environ:
+ # We are cross-compiling for one of the relevant platforms
+ if get_config_var('ANDROID_API_LEVEL') != 0:
+ link_libpython = True
+ elif get_config_var('MACHDEP') == 'cygwin':
+ link_libpython = True
+
+ if link_libpython:
+ ldversion = get_config_var('LDVERSION')
+ return ext.libraries + ['python' + ldversion]
return ext.libraries