Skip to content

fix: pass -undefined dynamic_lookup via CARGO_ENCODED_RUSTFLAGS on macOS#3083

Merged
messense merged 2 commits intoPyO3:mainfrom
messense:fix/macos-pyo3-dep-linker-args
Mar 12, 2026
Merged

fix: pass -undefined dynamic_lookup via CARGO_ENCODED_RUSTFLAGS on macOS#3083
messense merged 2 commits intoPyO3:mainfrom
messense:fix/macos-pyo3-dep-linker-args

Conversation

@messense
Copy link
Member

Pass -C link-arg=-undefined and -C link-arg=dynamic_lookup via CARGO_ENCODED_RUSTFLAGS instead of cargo rustc args so they apply to all crates in the dependency graph, not just the top-level crate.

This fixes link errors on macOS when a dependency also uses pyo3 with a cdylib crate-type target.

The install_name flag remains in cargo rustc args since it is specific to the final output artifact.

Closes #1080

…n macOS

Pass `-C link-arg=-undefined` and `-C link-arg=dynamic_lookup` via
`CARGO_ENCODED_RUSTFLAGS` instead of `cargo rustc` args so they apply
to all crates in the dependency graph, not just the top-level crate.

This fixes link errors on macOS when a dependency also uses pyo3 with a
`cdylib` crate-type target.

The `install_name` flag remains in `cargo rustc` args since it is
specific to the final output artifact.

Closes PyO3#1080
@messense messense requested a review from Copilot March 12, 2026 12:09
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adjust macOS PyO3 linking configuration so -undefined dynamic_lookup is applied across the entire dependency graph via CARGO_ENCODED_RUSTFLAGS, while keeping install_name scoped to the final artifact via cargo rustc args (fixing macOS link errors when dependencies also build PyO3 cdylib crates).

Changes:

  • Thread rustflags into the macOS PyO3 linker configuration helper.
  • Add -C link-arg=-undefined and -C link-arg=dynamic_lookup via CARGO_ENCODED_RUSTFLAGS.
  • Keep install_name as a cargo rustc argument and improve related debug logging.

You can also share your feedback on Copilot code review. Take the survey.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@messense messense merged commit 74baa67 into PyO3:main Mar 12, 2026
44 of 45 checks passed
@messense messense deleted the fix/macos-pyo3-dep-linker-args branch March 12, 2026 15:03
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.

Link errors on macOS when a dependency which also uses pyo3 has a cdylib target

2 participants