Open raphaelcohn opened 3 years ago
error: could not find native static library `c`, perhaps an -L flag is missing?
error: aborting due to previous error
error: could not compile `libc`
Caused by:
process didn't exit successfully: `CARGO=/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/bin/cargo CARGO_CRATE_NAME=libc CARGO_MANIFEST_DIR=/home/han/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.88 CARGO_PKG_AUTHORS='The Rust Project Developers' CARGO_PKG_DESCRIPTION='Raw FFI bindings to platform libraries like libc.
' CARGO_PKG_HOMEPAGE='https://github.com/rust-lang/libc' CARGO_PKG_LICENSE='MIT OR Apache-2.0' CARGO_PKG_LICENSE_FILE='' CARGO_PKG_NAME=libc CARGO_PKG_REPOSITORY='https://github.com/rust-lang/libc' CARGO_PKG_VERSION=0.2.88 CARGO_PKG_VERSION_MAJOR=0 CARGO_PKG_VERSION_MINOR=2 CARGO_PKG_VERSION_PATCH=88 CARGO_PKG_VERSION_PRE='' LD_LIBRARY_PATH='/usr/obj/rust/debug/deps:/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib:/home/han/.rustup/toolchains/nightly-x86_64-unknown-linux-musl/lib' OUT_DIR=/usr/obj/rust/x86_64-unknown-linux-musl/debug/build/libc-4cf2a7bffddd2e5d/out RUSTC_BOOTSTRAP=1 rustc --crate-name libc /home/han/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.88/src/lib.rs --error-format=json --json=diagnostic-rendered-ansi,artifacts --crate-type lib --emit=dep-info,metadata,link -C embed-bitcode=no -C debuginfo=2 --cfg 'feature="align"' --cfg 'feature="rustc-dep-of-std"' --cfg 'feature="rustc-std-workspace-core"' -C metadata=d244570cd2e0e60e -C extra-filename=-d244570cd2e0e60e --out-dir /usr/obj/rust/x86_64-unknown-linux-musl/debug/deps --target x86_64-unknown-linux-musl -Z force-unstable-if-unmarked -L dependency=/usr/obj/rust/x86_64-unknown-linux-musl/debug/deps -L dependency=/usr/obj/rust/debug/deps --extern rustc_std_workspace_core=/usr/obj/rust/x86_64-unknown-linux-musl/debug/deps/librustc_std_workspace_core-597cd0340bdb6a9d.rmeta --cap-lints warn -Clinker=ld.lld -Ctarget-feature=-crt-static --cfg freebsd11 --cfg libc_priv_mod_use --cfg libc_union --cfg libc_const_size_of --cfg libc_align --cfg libc_core_cvoid --cfg libc_packedN --cfg libc_cfg_target_vendor --cfg libc_thread_local` (exit status: 1)
It also failed on a musl system
A workaround for this is:
export RUSTFLAGS="-Lnative=/usr/lib"
(replace /usr/lib
with the path to libc.a
)
And a fix would be like https://github.com/rust-lang/libc/pull/1327 plus some adjustment in rustbuild like https://github.com/rust-lang/rust/pull/85600 to copy libc.a
into self-contained
directory.
This also happens for me on x86_64-unknown-linux-gnu; you can clearly see that it tries to compile core and std from the wrong toolchain.
I'm cross compiling for a linux musl target on MacOS, using the latest version of the homebrew musl-cross package. This works fine for normal work I do. However, when attempting to do a standard build, the libc rust crate fails with
error: could not find native static library
c, perhaps an -L flag is missing?
. Rightly so, as it has been linked added as a dependency torustc
command line (long trace below).This is because libc is odd; it doesn't emit use
cargo:rustc-link-search
in it's build script,build.rs
. A patch to do this back in 2015 was rejected because it's 'fixed upstream' (https://github.com/rust-lang/libc/pull/17) in rust itself (https://github.com/rust-lang/rust/commit/52862e4cda1ff72e52dfaea21cf82ae93725b3be). I have to say, I didn't follow this reasoning.This is a place where one would like to inject a custom flag - I know where and how to search for the libc - but I can only do so by modifying
RUSTFLAGS
, which affects everything else being built. Of course, I could write a rustc wrapper script, do a bit of argument sense checking, and then call rustc, but that's... work. (As an aside, when doing controlled, reproducible builds, I do this a lot, unsettingPATH
and then providing shim wrappers for tools until I build up a profile of what's needed to do a reproducible build, especially if build tools calldate
and the like).This seems related to #14 and other issues.