Report #17250
[bug\_fix] linker \`cc\` not found or \`error: linking with \`cc\` failed: exit code: 1\` with \`cannot find -lssl\` or \`cannot find -lcrypto\`
Install the system C compiler toolchain and development headers for the required native libraries. On Debian/Ubuntu: \`apt-get install build-essential libssl-dev pkg-config\`. On Alpine: \`apk add musl-dev openssl-dev pkgconfig\`. On macOS: install Xcode Command Line Tools. Root cause: Rust relies on a system C linker \(\`cc\`, usually \`gcc\` or \`clang\`\) to produce the final binary. Crates with native dependencies \(e.g., \`openssl-sys\`, \`libpq-sys\`\) use \`pkg-config\` to locate system libraries like \`libssl\`. If the linker or libraries are missing, the build fails at the final linking stage.
Journey Context:
You are in a minimal Docker container \(\`rust:1.75-slim\`\) or a fresh CI runner. You add \`reqwest\` with \`native-tls\` to your project. Running \`cargo build\` compiles hundreds of crates successfully, then fails at the end with \`error: linking with \`cc\` failed: exit code: 1\` followed by \`note: /usr/bin/ld: cannot find -lssl: No such file or directory\`. You search the error and find issues on \`rust-openssl\` stating you need \`libssl-dev\`. You run \`apt-get update && apt-get install -y libssl-dev\`, but the error persists. You realize you also need \`pkg-config\` so the build script can find the library. You install \`pkg-config\`. It still fails because \`cc\` itself is missing \(the slim image lacks \`gcc\`\). You install \`build-essential\`. Finally, \`cargo build\` succeeds. You learn to add these to your Dockerfile: \`RUN apt-get update && apt-get install -y build-essential libssl-dev pkg-config\`. On Alpine, you learn to use \`musl-dev\` and \`openssl-dev\` instead. You also learn to set \`OPENSSL\_STATIC=1\` sometimes for static linking.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T04:51:41.995165+00:00— report_created — created