Preserve C++ shared linker parameters - #425
Conversation
MohammedAlkindi
left a comment
There was a problem hiding this comment.
The change looks right to me for a reason the description undersells: it makes the strip and the re-prepend symmetric again.
The reconstruction two lines down is
linker = env + aix + compiler_cxx_ne + paramsso params has to be the linker command with compiler_cxx_ne removed. Stripping against linker_exe_ne while re-prepending compiler_cxx_ne means the two halves disagree whenever linker_exe_cxx and compiler_cxx differ, and _linker_params falls back to dropping just the first element when its prefix does not match. That is how -shared goes missing. After this change the same value is stripped and re-prepended, which is what the surrounding code already assumes.
Verified on Windows 11, Python 3.13.13. These tests are mock-based so they run off-platform:
main 7 passed
this PR 8 passed
The new test fails on unmodified source, checked by restoring only unix.py from main and keeping the test:
FAILED TestUnixCCompiler::test_cxx_shared_linker_preserves_shared_flag
E At index 1 diff: '-o' != '-shared'
Two things I could not check, stated so they are not mistaken for covered.
I did not reproduce the original symptom. #388 is a real Ubuntu C++ shared link failing, and this box is Windows, so what I exercised is the parameter-construction logic under mocks, not an actual g++ -shared invocation. Someone on Ubuntu confirming the built command would be worth more than this.
self.linker_exe_cxx now has one fewer reader in this function. It is still used for the executable path a few lines up, so nothing is orphaned, but if the intent was for the executable and shared paths to derive from the same source that is a design question rather than something this PR needs to answer.
Not a maintainer, just reporting what ran here.
Fixes #388
Summary
When the C++ linker command contains
-shared, Unix compiler parameter extraction used the executable linker command instead of the pure C++ compiler command. On Ubuntu-style configurations this caused the linker parameters to be removed before constructing the final command.This change extracts the linker parameters from
compiler_cxx_ne, preserving-sharedfor C++ shared-library links. A regression test covers the configuration where both C++ linker commands includec++ -shared.Validation
tox -e py— passedpytest distutils/compilers/C/tests/test_unix.py— passedgit diff --checkpassed