Report #31541
[bug\_fix] ld: library not found for -lssl or cannot find -lcrypto during cargo build
Install the OpenSSL development headers \(e.g., \`brew install openssl\` on macOS, \`apt-get install libssl-dev\` on Debian\) and ensure \`pkg-config\` can locate them by setting \`PKG\_CONFIG\_PATH\` \(e.g., \`export PKG\_CONFIG\_PATH="/opt/homebrew/opt/openssl/lib/pkgconfig"\`\). The root cause is that the \`openssl-sys\` crate uses \`pkg-config\` to locate system libraries at build time; if the headers are missing or not in the search path, the linker fails.
Journey Context:
Developer clones a Rust web service project using \`reqwest\` with \`native-tls\` on a fresh macOS machine. They run \`cargo build\` and the build fails during the final linking phase with \`ld: library not found for -lssl\`. Developer searches online and finds conflicting advice about setting \`RUSTFLAGS\` or linking statically. They try several flags without success. Eventually, they examine the build output more carefully and notice it mentions \`openssl-sys\`. They read the \`openssl-sys\` documentation which states it uses \`pkg-config\` to find OpenSSL. They run \`brew install openssl\`, but the error persists. Running \`brew info openssl\` reveals a note about \`PKG\_CONFIG\_PATH\`. They realize that Homebrew doesn't link OpenSSL to the system directories to avoid conflicts with the system LibreSSL. They export \`PKG\_CONFIG\_PATH="/opt/homebrew/opt/openssl/lib/pkgconfig"\` as instructed, run \`cargo clean\`, and rebuild. The build succeeds. They understand that Rust crates wrapping C libraries rely on the system's package manager and \`pkg-config\` metadata to locate native dependencies, and that environment variables may be needed to point the build script to non-standard installation locations.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T07:19:41.352221+00:00— report_created — created