Index: Lib/distutils/cygwinccompiler.py =================================================================== --- Lib/distutils/cygwinccompiler.py (revision 76451) +++ Lib/distutils/cygwinccompiler.py (working copy) @@ -137,7 +137,8 @@ # __init__ () - def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): + def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts, + target_lang): if ext == '.rc' or ext == '.res': # gcc needs '.res' and '.rc' compiled to object files !!! try: @@ -145,8 +146,18 @@ except DistutilsExecError, msg: raise CompileError, msg else: # for other files use the C-compiler + if target_lang == 'c++': + # Use C++ compiler but combine unique arguments from both + # C and C++ compilers + compiler = [self.compiler_cxx[0]] + for token in self.compiler_cxx[1:]: + if token not in self.compiler_so[1:]: + compiler.append(token) + compiler += self.compiler_so[1:] + else: + compiler = self.compiler_so try: - self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + + self.spawn(compiler + cc_args + [src, '-o', obj] + extra_postargs) except DistutilsExecError, msg: raise CompileError, msg Index: Lib/distutils/mwerkscompiler.py =================================================================== --- Lib/distutils/mwerkscompiler.py (revision 76451) +++ Lib/distutils/mwerkscompiler.py (working copy) @@ -67,7 +67,8 @@ debug=0, extra_preargs=None, extra_postargs=None, - depends=None): + depends=None, + target_lang=None): (output_dir, macros, include_dirs) = \ self._fix_compile_args (output_dir, macros, include_dirs) self.__sources = sources Index: Lib/distutils/msvccompiler.py =================================================================== --- Lib/distutils/msvccompiler.py (revision 76451) +++ Lib/distutils/msvccompiler.py (working copy) @@ -349,7 +349,8 @@ def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, - extra_preargs=None, extra_postargs=None, depends=None): + extra_preargs=None, extra_postargs=None, depends=None, + target_lang=None): if not self.initialized: self.initialize() macros, objects, extra_postargs, pp_opts, build = \ Index: Lib/distutils/ccompiler.py =================================================================== --- Lib/distutils/ccompiler.py (revision 76451) +++ Lib/distutils/ccompiler.py (working copy) @@ -631,7 +631,7 @@ def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, extra_preargs=None, - extra_postargs=None, depends=None): + extra_postargs=None, depends=None, target_lang=None): """Compile one or more source files. 'sources' must be a list of filenames, most likely C/C++ @@ -678,6 +678,9 @@ supports dependency tracking, but only at a coarse granularity. + 'target_lang' is a string that specifies the language of the + sources. + Raises CompileError on failure. """ @@ -694,12 +697,14 @@ src, ext = build[obj] except KeyError: continue - self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts) + self._compile(obj, src, ext, cc_args, extra_postargs, pp_opts, + target_lang) # Return *all* object filenames, not just the ones we just built. return objects - def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): + def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts, + target_lang): """Compile 'src' to product 'obj'.""" # A concrete compiler class that does not override compile() Index: Lib/distutils/bcppcompiler.py =================================================================== --- Lib/distutils/bcppcompiler.py (revision 76451) +++ Lib/distutils/bcppcompiler.py (working copy) @@ -84,7 +84,8 @@ def compile(self, sources, output_dir=None, macros=None, include_dirs=None, debug=0, - extra_preargs=None, extra_postargs=None, depends=None): + extra_preargs=None, extra_postargs=None, depends=None, + target_lang=None): macros, objects, extra_postargs, pp_opts, build = \ self._setup_compile(output_dir, macros, include_dirs, sources, Index: Lib/distutils/unixccompiler.py =================================================================== --- Lib/distutils/unixccompiler.py (revision 76451) +++ Lib/distutils/unixccompiler.py (working copy) @@ -165,12 +165,22 @@ except DistutilsExecError, msg: raise CompileError, msg - def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): - compiler_so = self.compiler_so + def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts, + target_lang): + if target_lang == 'c++': + # Use C++ compiler but combine unique arguments from both + # C and C++ compilers + compiler = [self.compiler_cxx[0]] + for token in self.compiler_cxx[1:]: + if token not in self.compiler_so[1:]: + compiler.append(token) + compiler += self.compiler_so[1:] + else: + compiler = self.compiler_so if sys.platform == 'darwin': - compiler_so = _darwin_compiler_fixup(compiler_so, cc_args + extra_postargs) + compiler = _darwin_compiler_fixup(compiler, cc_args + extra_postargs) try: - self.spawn(compiler_so + cc_args + [src, '-o', obj] + + self.spawn(compiler + cc_args + [src, '-o', obj] + extra_postargs) except DistutilsExecError, msg: raise CompileError, msg Index: Lib/distutils/command/build_ext.py =================================================================== --- Lib/distutils/command/build_ext.py (revision 76451) +++ Lib/distutils/command/build_ext.py (working copy) @@ -472,13 +472,17 @@ for undef in ext.undef_macros: macros.append((undef,)) + # Detect target language, if not provided + language = ext.language or self.compiler.detect_language(sources) + objects = self.compiler.compile(sources, output_dir=self.build_temp, macros=macros, include_dirs=ext.include_dirs, debug=self.debug, extra_postargs=extra_args, - depends=ext.depends) + depends=ext.depends, + target_lang=language) # XXX -- this is a Vile HACK! # @@ -498,9 +502,6 @@ 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), Index: Lib/distutils/emxccompiler.py =================================================================== --- Lib/distutils/emxccompiler.py (revision 76451) +++ Lib/distutils/emxccompiler.py (working copy) @@ -74,7 +74,8 @@ # __init__ () - def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts): + def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts, + target_lang): if ext == '.rc': # gcc requires '.rc' compiled to binary ('.res') files !!! try: @@ -82,8 +83,18 @@ except DistutilsExecError, msg: raise CompileError, msg else: # for other files use the C-compiler + if target_lang == 'c++': + # Use C++ compiler but combine unique arguments from both + # C and C++ compilers + compiler = [self.compiler_cxx[0]] + for token in self.compiler_cxx[1:]: + if token not in self.compiler_so[1:]: + compiler.append(token) + compiler += self.compiler_so[1:] + else: + compiler = self.compiler_so try: - self.spawn(self.compiler_so + cc_args + [src, '-o', obj] + + self.spawn(compiler + cc_args + [src, '-o', obj] + extra_postargs) except DistutilsExecError, msg: raise CompileError, msg