Skip to content

Preserve C++ shared linker parameters - #425

Closed
fff122 wants to merge 1 commit into
pypa:mainfrom
fff122:fix-cxx-shared-link-388
Closed

Preserve C++ shared linker parameters#425
fff122 wants to merge 1 commit into
pypa:mainfrom
fff122:fix-cxx-shared-link-388

Conversation

@fff122

@fff122 fff122 commented Aug 14, 2026

Copy link
Copy Markdown

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 -shared for C++ shared-library links. A regression test covers the configuration where both C++ linker commands include c++ -shared.

Validation

  • tox -e py — passed
  • pytest distutils/compilers/C/tests/test_unix.py — passed
  • Ruff check passed
  • git diff --check passed

@MohammedAlkindi MohammedAlkindi left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 + params

so 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.

@fff122 fff122 closed this by deleting the head repository Aug 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] C++ shared library linking fails on Ubuntu: -shared flag stripped in transformation block

2 participants