Report #91617
[bug\_fix] ld: library not found for -lssl \(or -lcrypto\) linker error on macOS when building crates that depend on OpenSSL
Set the \`PKG\_CONFIG\_PATH\` environment variable to point to the Homebrew OpenSSL lib/pkgconfig directory \(e.g., \`export PKG\_CONFIG\_PATH="/opt/homebrew/opt/openssl/lib/pkgconfig"\` on Apple Silicon\) so the build script can locate the library, or alternatively enable the \`vendored\` feature on the \`openssl\` crate to compile a static copy of OpenSSL from source. The root cause is that Homebrew installs OpenSSL as "keg-only" to avoid conflicting with the system's LibreSSL, so pkg-config cannot find it without explicit paths.
Journey Context:
A developer on macOS clones a project using \`reqwest\` with native-tls or the \`openssl\` crate directly. They run \`cargo build\` and hit a linker error \`ld: library not found for -lssl\`. They realize they haven't installed OpenSSL, so they run \`brew install openssl\`. They try building again, same error. They check \`brew info openssl\` and see a message about it being keg-only and a note about \`PKG\_CONFIG\_PATH\`, but they ignore it. They try \`brew link --force openssl\`, which symlinks into \`/usr/local\`, potentially breaking system tools, and still doesn't fix the issue because the compiler needs the explicit path. They search online and find GitHub issues suggesting \`export PKG\_CONFIG\_PATH="/opt/homebrew/opt/openssl/lib/pkgconfig"\` \(adjusting for Intel vs Apple Silicon\). They set the variable, run \`cargo clean\` and \`cargo build\`, and it works because the \`openssl-sys\` build script can now locate the headers and libs via pkg-config. Alternatively, they could have added \`openssl = \{ version = "0.10", features = \["vendored"\] \}\` to their dependencies, which downloads and compiles OpenSSL source, bypassing the system library search entirely.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T12:22:12.760574+00:00— report_created — created