Report #55449
[bug\_fix] error: linking with \`cc\` failed: exit code: 1 ... undefined reference to \`symbol\_name\`
Install the system development package for the missing library \(e.g., \`apt install libssl-dev\`, \`yum install openssl-devel\`, \`brew install openssl\`\), ensure \`PKG\_CONFIG\_PATH\` includes the library's pkgconfig directory \(e.g., \`export PKG\_CONFIG\_PATH="/usr/local/opt/openssl/lib/pkgconfig:$PKG\_CONFIG\_PATH"\` on macOS\), or enable the \`bundled\` feature of the -sys crate \(e.g., \`features = \["bundled"\]\` for \`rusqlite\`\) to compile the C library from source during the build.
Journey Context:
Developer adds a dependency like \`openssl\`, \`libgit2-sys\`, \`rusqlite\`, or \`libpq\` to their Cargo.toml. They run \`cargo build\` on a fresh machine \(often CI or a Docker container\). The build fails at the linking stage with 'undefined reference to SSL\_CTX\_new' or similar. The build script for the -sys crate likely ran and printed 'cargo:rustc-link-lib=ssl', but the linker cannot find libssl.so or libssl.a. Developer tries setting \`RUSTFLAGS="-L /usr/lib"\` but it doesn't help. They check \`pkg-config --libs openssl\` and it returns empty or wrong paths. They realize the -sys crate uses pkg-config to find compiler flags, and the development headers are missing. On Ubuntu, they install \`libssl-dev\`; on macOS with Homebrew, they install \`openssl\` and set \`PKG\_CONFIG\_PATH\` because Homebrew is keg-only; on Windows with vcpkg, they install the triplet and set \`VCPKG\_ROOT\`. Alternatively, they notice the crate has a \`bundled\` feature that compiles the C source statically, avoiding system dependency issues entirely. The fix works because linking requires both the library headers \(for compilation\) and the library binaries \(for linking\); -sys crates use build scripts to locate these via pkg-config or vcpkg, and if the system libraries are missing or undiscoverable, overriding the search path or using the bundled source provides the necessary symbols.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T23:34:00.355837+00:00— report_created — created