Skip to content

Commit 1ebceb4

Browse files
committed
Additional link args and troubleshooting for MacOS
Fixes #1800 Documents issues linking with the system python (`/usr/bin/python3`) as well as reemphasizes the need for `--no-default-features` with `cargo test` on MacOS
1 parent 6503128 commit 1ebceb4

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

guide/src/building_and_distribution.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,29 @@ rustflags = [
135135
]
136136
```
137137

138+
Using the MacOS system python3 (`/usr/bin/python3`, as opposed to python installed via homebrew, pyenv, nix, etc.) may result in runtime errors such as `Library not loaded: @rpath/Python3.framework/Versions/3.8/Python3`. These can be resolved with another addition to `.cargo/config.toml`:
139+
140+
```toml
141+
[build]
142+
rustflags = [
143+
"-C", "link-args=-Wl,-rpath,/Library/Developer/CommandLineTools/Library/Frameworks",
144+
]
145+
```
146+
147+
Alternatively, on rust >= 1.56, one can include in `build.rs`:
148+
149+
```rust
150+
fn main() {
151+
println!(
152+
"cargo:rustc-link-arg=-Wl,-rpath,/Library/Developer/CommandLineTools/Library/Frameworks"
153+
);
154+
}
155+
```
156+
157+
For more discussion on and workarounds for MacOS linking problems [see this issue](https://github.com/PyO3/pyo3/issues/1800#issuecomment-906786649).
158+
159+
Finally, don't forget that on MacOS the `extension-module` feature will cause `cargo test` to fail without the `--no-default-features` flag (see [the FAQ](https://pyo3.rs/main/faq.html#i-cant-run-cargo-test-im-having-linker-issues-like-symbol-not-found-or-undefined-reference-to-_pyexc_systemerror)).
160+
138161
### The `extension-module` feature
139162

140163
PyO3's `extension-module` feature is used to disable [linking](https://en.wikipedia.org/wiki/Linker_(computing)) to `libpython` on unix targets.

0 commit comments

Comments
 (0)