1diff --git a/setuptools/_distutils/cygwinccompiler.py b/setuptools/_distutils/cygwinccompiler.py
2index 2c4da5b5..e2cd8803 100644
3--- a/setuptools/_distutils/cygwinccompiler.py
4+++ b/setuptools/_distutils/cygwinccompiler.py
5@@ -97,14 +97,19 @@ class CygwinCCompiler(UnixCCompiler):
6 self.cxx = os.environ.get('CXX', 'g++')
7
8 self.linker_dll = self.cc
9+ self.linker_dll_cxx = self.cxx
10 shared_option = "-shared"
11
12 self.set_executables(
13 compiler='%s -mcygwin -O -Wall' % self.cc,
14 compiler_so='%s -mcygwin -mdll -O -Wall' % self.cc,
15 compiler_cxx='%s -mcygwin -O -Wall' % self.cxx,
16+ compiler_so_cxx='%s -mcygwin -mdll -O -Wall' % self.cxx,
17 linker_exe='%s -mcygwin' % self.cc,
18 linker_so=('{} -mcygwin {}'.format(self.linker_dll, shared_option)),
19+ linker_exe_cxx='%s -mcygwin' % self.cxx,
20+ linker_so_cxx=('%s -mcygwin %s' %
21+ (self.linker_dll_cxx, shared_option)),
22 )
23
24 # Include the appropriate MSVC runtime library if Python was built
25@@ -136,9 +141,12 @@ class CygwinCCompiler(UnixCCompiler):
26 raise CompileError(msg)
27 else: # for other files use the C-compiler
28 try:
29- self.spawn(
30- self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs
31- )
32+ if self.detect_language(src) == 'c++':
33+ self.spawn(self.compiler_so_cxx + cc_args + [src, '-o', obj] +
34+ extra_postargs)
35+ else:
36+ self.spawn(
37+ self.compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
38 except DistutilsExecError as msg:
39 raise CompileError(msg)
40
41@@ -275,9 +283,12 @@ class Mingw32CCompiler(CygwinCCompiler):
42 self.set_executables(
43 compiler='%s -O -Wall' % self.cc,
44 compiler_so='%s -mdll -O -Wall' % self.cc,
45+ compiler_so_cxx='%s -mdll -O -Wall' % self.cxx,
46 compiler_cxx='%s -O -Wall' % self.cxx,
47 linker_exe='%s' % self.cc,
48 linker_so='{} {}'.format(self.linker_dll, shared_option),
49+ linker_exe_cxx='%s' % self.cxx,
50+ linker_so_cxx='%s %s' % (self.linker_dll_cxx, shared_option)
51 )
52
53 # Maybe we should also append -mthreads, but then the finished
54diff --git a/setuptools/_distutils/sysconfig.py b/setuptools/_distutils/sysconfig.py
55index 3dd8185f..cb374a94 100644
56--- a/setuptools/_distutils/sysconfig.py
57+++ b/setuptools/_distutils/sysconfig.py
58@@ -289,6 +289,7 @@ def customize_compiler(compiler): # noqa: C901
59 cflags,
60 ccshared,
61 ldshared,
62+ ldcxxshared,
63 shlib_suffix,
64 ar,
65 ar_flags,
66@@ -298,11 +299,14 @@ def customize_compiler(compiler): # noqa: C901
67 'CFLAGS',
68 'CCSHARED',
69 'LDSHARED',
70+ 'LDCXXSHARED',
71 'SHLIB_SUFFIX',
72 'AR',
73 'ARFLAGS',
74 )
75
76+ cxxflags = cflags
77+
78 if 'CC' in os.environ:
79 newcc = os.environ['CC']
80 if 'LDSHARED' not in os.environ and ldshared.startswith(cc):
81@@ -314,19 +318,27 @@ def customize_compiler(compiler): # noqa: C901
82 cxx = os.environ['CXX']
83 if 'LDSHARED' in os.environ:
84 ldshared = os.environ['LDSHARED']
85+ if 'LDCXXSHARED' in os.environ:
86+ ldcxxshared = os.environ['LDCXXSHARED']
87 if 'CPP' in os.environ:
88 cpp = os.environ['CPP']
89 else:
90 cpp = cc + " -E" # not always
91 if 'LDFLAGS' in os.environ:
92 ldshared = ldshared + ' ' + os.environ['LDFLAGS']
93+ ldcxxshared = ldcxxshared + ' ' + os.environ['LDFLAGS']
94 if 'CFLAGS' in os.environ:
95- cflags = cflags + ' ' + os.environ['CFLAGS']
96+ cflags = os.environ['CFLAGS']
97 ldshared = ldshared + ' ' + os.environ['CFLAGS']
98+ if 'CXXFLAGS' in os.environ:
99+ cxxflags = os.environ['CXXFLAGS']
100+ ldcxxshared = ldcxxshared + ' ' + os.environ['CXXFLAGS']
101 if 'CPPFLAGS' in os.environ:
102 cpp = cpp + ' ' + os.environ['CPPFLAGS']
103 cflags = cflags + ' ' + os.environ['CPPFLAGS']
104+ cxxflags = cxxflags + ' ' + os.environ['CPPFLAGS']
105 ldshared = ldshared + ' ' + os.environ['CPPFLAGS']
106+ ldcxxshared = ldcxxshared + ' ' + os.environ['CPPFLAGS']
107 if 'AR' in os.environ:
108 ar = os.environ['AR']
109 if 'ARFLAGS' in os.environ:
110@@ -335,13 +347,17 @@ def customize_compiler(compiler): # noqa: C901
111 archiver = ar + ' ' + ar_flags
112
113 cc_cmd = cc + ' ' + cflags
114+ cxx_cmd = cxx + ' ' + cxxflags
115 compiler.set_executables(
116 preprocessor=cpp,
117 compiler=cc_cmd,
118 compiler_so=cc_cmd + ' ' + ccshared,
119- compiler_cxx=cxx,
120+ compiler_cxx=cxx_cmd,
121+ compiler_so_cxx=cxx_cmd + ' ' + ccshared,
122 linker_so=ldshared,
123+ linker_so_cxx=ldcxxshared,
124 linker_exe=cc,
125+ linker_exe_cxx=cxx,
126 archiver=archiver,
127 )
128
129diff --git a/setuptools/_distutils/unixccompiler.py b/setuptools/_distutils/unixccompiler.py
130index 4ab771a4..17abac83 100644
131--- a/setuptools/_distutils/unixccompiler.py
132+++ b/setuptools/_distutils/unixccompiler.py
133@@ -116,9 +116,12 @@ class UnixCCompiler(CCompiler):
134 'preprocessor': None,
135 'compiler': ["cc"],
136 'compiler_so': ["cc"],
137- 'compiler_cxx': ["cc"],
138+ 'compiler_cxx': ["c++"],
139+ 'compiler_so_cxx': ["c++"],
140 'linker_so': ["cc", "-shared"],
141+ 'linker_so_cxx': ["c++", "-shared"],
142 'linker_exe': ["cc"],
143+ 'linker_exe_cxx': ["c++", "-shared"],
144 'archiver': ["ar", "-cr"],
145 'ranlib': None,
146 }
147@@ -182,8 +185,13 @@ class UnixCCompiler(CCompiler):
148
149 def _compile(self, obj, src, ext, cc_args, extra_postargs, pp_opts):
150 compiler_so = compiler_fixup(self.compiler_so, cc_args + extra_postargs)
151+ compiler_so_cxx = compiler_fixup(self.compiler_so_cxx, cc_args + extra_postargs)
152 try:
153- self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
154+ if self.detect_language(src) == 'c++':
155+ self.spawn(compiler_so_cxx + cc_args + [ src, '-o', obj] +
156+ extra_postargs)
157+ else:
158+ self.spawn(compiler_so + cc_args + [src, '-o', obj] + extra_postargs)
159 except DistutilsExecError as msg:
160 raise CompileError(msg)
161
162@@ -251,7 +259,8 @@ class UnixCCompiler(CCompiler):
163 # building an executable or linker_so (with shared options)
164 # when building a shared library.
165 building_exe = target_desc == CCompiler.EXECUTABLE
166- linker = (self.linker_exe if building_exe else self.linker_so)[:]
167+ linker = (self.linker_exe if building_exe else (self.linker_so_cxx if
168+ target_lang == "c++" else self.linker_so))[:]
169
170 if target_lang == "c++" and self.compiler_cxx:
171 env, linker_ne = _split_env(linker)