Skip to content

Commit 06e9953

Browse files
bpo-35198 Fix C++ extension compilation on AIX (GH-10437)
For C++ extensions, distutils tries to replace the C compiler with the C++ compiler, but it assumes that C compiler is the first element after any environment variables set. On AIX, linking goes through ld_so_aix, so it is the first element and the compiler is the next element. Thus the replacement is faulty: ld_so_aix gcc ... -> g++ gcc ... Also, it assumed that self.compiler_cxx had only 1 element or that there were the same number of elements as the linker has and in the same order. This might not be the case, so instead concatenate everything together. (cherry picked from commit 800d5cd) Co-authored-by: Kevin Adler <[email protected]>
1 parent 84fa6b9 commit 06e9953

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

Lib/distutils/unixccompiler.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,15 @@ def link(self, target_desc, objects,
188188
i = 1
189189
while '=' in linker[i]:
190190
i += 1
191-
linker[i] = self.compiler_cxx[i]
191+
192+
if os.path.basename(linker[i]) == 'ld_so_aix':
193+
# AIX platforms prefix the compiler with the ld_so_aix
194+
# script, so we need to adjust our linker index
195+
offset = 1
196+
else:
197+
offset = 0
198+
199+
linker[i+offset] = self.compiler_cxx[i]
192200

193201
if sys.platform == 'darwin':
194202
linker = _osx_support.compiler_fixup(linker, ld_args)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix C++ extension compilation on AIX

0 commit comments

Comments
 (0)