Report #85995
[bug\_fix] Cargo linking with \`cc\` failed: ld: library not found for -lssl \(or -lcrypto\) on macOS
Install OpenSSL via Homebrew \(\`brew install openssl\`\), then export \`PKG\_CONFIG\_PATH="/opt/homebrew/opt/openssl/lib/pkgconfig"\` \(Apple Silicon\) or \`/usr/local/opt/openssl/lib/pkgconfig\` \(Intel\) before building. Alternatively, switch to the \`rustls-tls\` feature in crates like \`reqwest\` to avoid linking to system OpenSSL entirely. The root cause is that the linker cannot find the OpenSSL libraries in the default search paths on macOS, which does not ship with development headers for OpenSSL.
Journey Context:
Developer on macOS adds \`reqwest = \{ version = "0.11", features = \["native-tls"\] \}\` to Cargo.toml and tries to build. The build fails at the linking stage with \`ld: library not found for -lssl\`. Developer knows they have OpenSSL installed via \`brew install openssl\`, but the error persists. They try \`export OPENSSL\_DIR=/opt/homebrew/opt/openssl\` based on Stack Overflow posts, but the error changes to \`ld: library not found for -lcrypto\`. They realize that on Apple Silicon Macs, Homebrew uses \`/opt/homebrew\` instead of \`/usr/local\`, but the \`pkg-config\` files aren't being found. They try \`export PKG\_CONFIG\_PATH=/opt/homebrew/lib/pkgconfig\` but that breaks other builds. Eventually, they find the specific path \`/opt/homebrew/opt/openssl/lib/pkgconfig\` and export it, allowing \`pkg-config\` to correctly pass the linker flags. Alternatively, they discover they can avoid the system dependency entirely by switching to \`features = \["rustls-tls"\]\`, which uses a pure Rust TLS implementation and eliminates the platform-specific linking requirement.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T02:55:32.043536+00:00— report_created — created