This patch fixes the following bugs:
[#413582] g++ must be called for c++ extensions
[#454030] distutils cannot link C++ code with GCC
topdir = "Lib/distutils"
* bcppcompiler.py
(BCPPCompiler.create_static_lib): Fixed prototype, removing extra_preargs
and extra_postargs parameters. Included target_lang parameter.
(BCPPCompiler.link): Included target_lang parameter.
* msvccompiler.py
(MSVCCompiler.create_static_lib): Fixed prototype, removing extra_preargs
and extra_postargs parameters. Included target_lang parameter.
(MSVCCompiler.link): Included target_lang parameter.
* ccompiler.py
(CCompiler): New language_map and language_order attributes, used by
CCompiler.detect_language().
(CCompiler.detect_language): New method, will return the language of
a given source, or list of sources. Individual source language is
detected using the language_map dict. When mixed sources are used,
language_order will stablish the language precedence.
(CCompiler.create_static_lib, CCompiler.link, CCompiler.link_executable,
CCompiler.link_shared_object, CCompiler.link_shared_lib):
Inlcuded target_lang parameter.
* cygwinccompiler.py
(CygwinCCompiler.link): Included target_lang parameter.
* emxccompiler.py
(EMXCCompiler.link): Included target_lang parameter.
* mwerkscompiler.py
(MWerksCompiler.link): Included target_lang parameter.
* extension.py
(Extension.__init__): New 'language' parameter/attribute, initialized
to None by default. If provided will overlap the automatic detection
made by CCompiler.detect_language(), in build_ext command.
* sysconfig.py
(customize_compiler): Check Makefile for CXX option, and also the
environment variable CXX. Use the resulting value in the 'compiler_cxx'
parameter of compiler.set_executables().
* unixccompiler.py
(UnixCCompiler): Included 'compiler_cxx' in executables dict, defaulting
to 'cc'.
(UnixCCompiler.create_static_lib): Included target_lang parameter.
(UnixCCompiler.link): Included target_lang parameter, and made
linker command use compiler_cxx, if target_lang is 'c++'.
* command/build_ext.py
(build_ext.build_extension): Pass new ext.language attribute
to compiler.link_shared_object()'s target_lang parameter. If
ext.language is not provided, detect language using
compiler.detect_language(sources) instead.
* command/config.py
(config._link): Pass already available lang parameter as target_lang
parameter of compiler.link_executable().
diff --git a/Lib/distutils/command/build_ext.py b/Lib/distutils/command/build_ext.py
index 934b457..4bfc20c 100644
--- a/Lib/distutils/command/build_ext.py
+++ b/Lib/distutils/command/build_ext.py
@@ -477,6 +477,9 @@
objects.extend(ext.extra_objects)
extra_args = ext.extra_link_args or []
+ # Detect target language, if not provided
+ language = ext.language or self.compiler.detect_language(sources)
+
self.compiler.link_shared_object(
objects, ext_filename,
libraries=self.get_libraries(ext),
@@ -485,7 +488,8 @@
extra_postargs=extra_args,
export_symbols=self.get_export_symbols(ext),
debug=self.debug,
- build_temp=self.build_temp)
+ build_temp=self.build_temp,
+ target_lang=language)
def swig_sources (self, sources):
diff --git a/Lib/distutils/command/config.py b/Lib/distutils/command/config.py
index 88b1586..9ebe0d9 100644
--- a/Lib/distutils/command/config.py
+++ b/Lib/distutils/command/config.py
@@ -148,7 +148,8 @@
prog = os.path.splitext(os.path.basename(src))[0]
self.compiler.link_executable([obj], prog,
libraries=libraries,
- library_dirs=library_dirs)
+ library_dirs=library_dirs,
+ target_lang=lang)
prog = prog + self.compiler.exe_extension
self.temp_files.append(prog)