Report #87836
[bug\_fix] linker \`cc\` not found or could not find native static library \`openssl\`
Install the system C compiler and development headers for the required native libraries. On Debian/Ubuntu: \`sudo apt-get install build-essential libssl-dev pkg-config\`. On Fedora/RHEL: \`sudo dnf install gcc openssl-devel pkgconfig\`. On macOS: \`xcode-select --install\` or \`brew install openssl pkg-config\` and ensure \`PKG\_CONFIG\_PATH\` includes \`/opt/homebrew/opt/openssl/lib/pkgconfig\` \(Apple Silicon\). On Windows: Install Visual Studio Build Tools with 'Desktop development with C\+\+' workload, or use \`cargo-xwin\` for cross-compilation. If system libs are in non-standard locations, set environment variables like \`OPENSSL\_DIR\` or \`PKG\_CONFIG\_PATH\` before building.
Journey Context:
The developer pulls a Rust project from GitHub onto a fresh Ubuntu 22.04 server or a minimal CI image \(like \`rust:slim\`\). They run \`cargo build --release\`. After compiling many Rust crates, the build fails with a cryptic message: 'linker \`cc\` not found' or 'error: linking with \`cc\` failed: exit status: 1' followed by 'note: /usr/bin/ld: cannot find -lssl: No such file or directory'. The developer searches the error and finds StackOverflow posts suggesting to install \`libssl-dev\`. They run \`apt-get install libssl-dev\` but the error persists or changes to 'pkg-config exited with status 1'. They realize \`pkg-config\` itself is missing and install it. They then encounter issues where \`pkg-config\` cannot find \`openssl\` because the version is too new or installed in a non-standard path \(common on macOS with Homebrew\). They try setting \`OPENSSL\_STATIC=1\` which fails because the static libs aren't present. They try \`cargo clean\` and rebuild, which doesn't help. The root cause is that Cargo delegates the final linking step to the platform's system linker \(gcc/ld on Linux, link.exe on Windows, ld64 on macOS\). When a crate depends on a \`-sys\` crate \(like \`openssl-sys\`\), that crate's build script emits directives like \`cargo:rustc-link-lib=ssl\`. The Rust compiler passes \`-lssl\` to the linker. If the linker cannot find \`libssl.so\` or \`libssl.a\` in its search path, or if the C compiler \`cc\` itself is missing, the build fails. The fix requires installing the C toolchain and the development packages \(headers and static/dynamic libs\) for the required system libraries, and potentially configuring environment variables like \`PKG\_CONFIG\_PATH\` so \`pkg-config\` can tell Cargo where to find them.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T06:01:03.415882+00:00— report_created — created