Skip to content

Commit b8c06ff

Browse files
committed
Respect CXX when parsing linker parameters for UNIX c++ targets
Previously, when parsing linker parameters for C++ targets, the CC variable was used to determine what the "prefix" of the command was in order to determine what the linker arguments were. If the value of LDCXXSHARED did not match CC, the first argument would be dropped as it was assumed to be the linker command. However, if the command was a wrapper, such as ccache, it could lead to compile problems as the generated command would be incorrect. In the following scenario: LDCXXSHARED="ccache g++ -shared -Wl,--enable-new-dtags" CC="ccache gcc" CXX="ccache g++" The command would be incorrectly parsed to: ccache g++ g++ -shared -Wl,--enable-new-dtags Now, the CXX value is used to improve the chances of parsing the linker arguments correctly to generate: ccache g++ -shared -Wl,--enable-new-dtags LDCXXSHARED and CXX still need to be in sync either in the environment or within the sysconfig variables in the CPython build for parsing to work correctly. The CXX value is now also respected when linking executable binaries. Signed-off-by: Vincent Fazio <[email protected]>
1 parent 24bd317 commit b8c06ff

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

distutils/compilers/C/unix.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -286,19 +286,18 @@ def link(
286286
# building an executable or linker_so (with shared options)
287287
# when building a shared library.
288288
building_exe = target_desc == base.Compiler.EXECUTABLE
289+
target_cxx = target_lang == "c++"
289290
linker = (
290-
self.linker_exe
291+
(self.linker_exe_cxx if target_cxx else self.linker_exe)
291292
if building_exe
292-
else (
293-
self.linker_so_cxx if target_lang == "c++" else self.linker_so
294-
)
293+
else (self.linker_so_cxx if target_cxx else self.linker_so)
295294
)[:]
296295

297-
if target_lang == "c++" and self.compiler_cxx:
296+
if target_cxx and self.compiler_cxx:
298297
env, linker_ne = _split_env(linker)
299298
aix, linker_na = _split_aix(linker_ne)
300299
_, compiler_cxx_ne = _split_env(self.compiler_cxx)
301-
_, linker_exe_ne = _split_env(self.linker_exe)
300+
_, linker_exe_ne = _split_env(self.linker_exe_cxx)
302301

303302
params = _linker_params(linker_na, linker_exe_ne)
304303
linker = env + aix + compiler_cxx_ne + params

0 commit comments

Comments
 (0)