I'm not sure if this is really the fault of cargo-zigbuild but as of ziglang 0.11.0, I get linker errors trying to cross compile to x86_64-unknown-linux-musl from multiple platforms with code that compiles fine using 0.10.1 (M1 mac and x86_64 linux boxes).
Here's a snippet that reproduces the issue
use std::fs::File;
use std::io::Write;
fn main() -> std::io::Result<()> {
let mut file = File::create("foo.txt")?;
file.write_all(b"Hello, world!")?;
Ok(())
}
Cross compiling should result in the undefined symbols:
❯ cargo zigbuild --target x86_64-unknown-linux-musl
Compiling zig-repro v0.1.0 (/Users/aarongriffin/Code/zig-repro)
error: linking with `/Users/aarongriffin/Library/Caches/cargo-zigbuild/0.17.0/zigcc-x86_64-unknown-linux-musl.sh` failed: exit status: 1
|
= note: LC_ALL="C" PATH="/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin:/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/aarch64-apple-darwin/bin/self-contained:/opt/homebrew/opt/openssl@3/bin:/opt/homebrew/opt/curl/bin:/opt/homebrew/bin:/opt/homebrew/sbin:/usr/local/bin:/System/Cryptexes/App/usr/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/Little Snitch.app/Contents/Components:/Library/Apple/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/local/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/bin:/var/run/com.apple.security.cryptexd/codex.system/bootstrap/usr/appleinternal/bin:/Users/aarongriffin/.cargo/bin:/Users/aarongriffin/Library/Application Support/JetBrains/Toolbox/scripts:/Users/aarongriffin/Library/Application Support/Coursier/bin" VSLANG="1033" "/Users/aarongriffin/Library/Caches/cargo-zigbuild/0.17.0/zigcc-x86_64-unknown-linux-musl.sh" "-m64" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/rcrt1.o" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crti.o" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtbeginS.o" "/var/folders/y5/06kg21m11clgt6x4qf8j5bgh0000gn/T/rustcvfZleQ/symbols.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.11i8kmlmvp9cqkkz.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.17r9nj3dgxuhb9t0.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.1xoal9fq6492aeup.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.27blpvy70ra654cl.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.29i9gwviy5pta2y6.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.2arfgwq1nmabvmds.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.2ia3wvo0he6rccer.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.3nnjfq7rxx3hyl2j.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.3s3qsxh5vs8vi68i.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.3wkuoig96qxninub.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.3wv2e3kyz59wetrt.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.41mz88y7svuy84h8.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.4kaeaoadnxmq01qu.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.4w2qeued6l01ut0r.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.4y4gkcp6b9po0vwr.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.cx6vjri81n7zt74.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.gqftvu6gokjr022.rcgu.o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c.j85959ewcv48pe0.rcgu.o" "-Wl,--as-needed" "-L" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps" "-L" "/Users/aarongriffin/Code/zig-repro/target/debug/deps" "-L" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib" "-Wl,-Bstatic" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-493936ddc336b3cf.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libpanic_unwind-3dd70cbadf3e1002.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libobject-3558ee77f8b1ad74.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libmemchr-10f2552578618c97.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libaddr2line-7b520da5a73d1918.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libgimli-3702969c0e889474.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_demangle-c0cc4c329ee15590.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd_detect-874514dffe09e03c.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libhashbrown-e3f573f6d5b58355.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_alloc-85dc525393d56c52.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libminiz_oxide-36ca93bbf21bf97c.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libadler-1041082638612281.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libunwind-e11982fd4ee76f53.rlib" "-lunwind" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libcfg_if-78634847bd9095da.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/liblibc-930f912cc77d37c5.rlib" "-lc" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/liballoc-8cc0612c0889f762.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/librustc_std_workspace_core-918df048a2f8e1f4.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libcore-d1705156e6561f5f.rlib" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libcompiler_builtins-9ad5603f71a0f0cc.rlib" "-Wl,-Bdynamic" "-Wl,--eh-frame-hdr" "-Wl,-z,noexecstack" "-nostartfiles" "-L" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib" "-L" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained" "-o" "/Users/aarongriffin/Code/zig-repro/target/x86_64-unknown-linux-musl/debug/deps/zig_repro-6398a6e43eab019c" "-Wl,--gc-sections" "-static-pie" "-Wl,-z,relro,-z,now" "-nodefaultlibs" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtendS.o" "/Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o"
= note: ld.lld: error: undefined symbol: fstat64
>>> referenced by fs.rs:1075 (library/std/src/sys/unix/fs.rs:1075)
>>> std-493936ddc336b3cf.std.7b49138af54fd575-cgu.0.rcgu.o:(std::fs::buffer_capacity_required::hc871770ed5ccad2e) in archive /Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-493936ddc336b3cf.rlib
>>> referenced by fs.rs:1075 (library/std/src/sys/unix/fs.rs:1075)
>>> std-493936ddc336b3cf.std.7b49138af54fd575-cgu.0.rcgu.o:(std::backtrace_rs::symbolize::gimli::mmap::h76fa57f673813473) in archive /Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-493936ddc336b3cf.rlib
ld.lld: error: undefined symbol: lseek64
>>> referenced by fs.rs:1192 (library/std/src/sys/unix/fs.rs:1192)
>>> std-493936ddc336b3cf.std.7b49138af54fd575-cgu.0.rcgu.o:(std::fs::buffer_capacity_required::hc871770ed5ccad2e) in archive /Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-493936ddc336b3cf.rlib
ld.lld: error: undefined symbol: stat64
>>> referenced by fs.rs:1591 (library/std/src/sys/unix/fs.rs:1591)
>>> std-493936ddc336b3cf.std.7b49138af54fd575-cgu.0.rcgu.o:(std::fs::metadata::hcda31e3dc0dbef7e) in archive /Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-493936ddc336b3cf.rlib
>>> referenced by fs.rs:1591 (library/std/src/sys/unix/fs.rs:1591)
>>> std-493936ddc336b3cf.std.7b49138af54fd575-cgu.0.rcgu.o:(std::sys::common::small_c_string::run_with_cstr_allocating::h0608e48c65cfc945) in archive /Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-493936ddc336b3cf.rlib
>>> referenced by fs.rs:1591 (library/std/src/sys/unix/fs.rs:1591)
>>> std-493936ddc336b3cf.std.7b49138af54fd575-cgu.0.rcgu.o:(std::backtrace_rs::symbolize::gimli::elf::debug_path_exists::h789d363560f56efc) in archive /Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-493936ddc336b3cf.rlib
ld.lld: error: undefined symbol: open64
>>> referenced by fs.rs:1056 (library/std/src/sys/unix/fs.rs:1056)
>>> std-493936ddc336b3cf.std.7b49138af54fd575-cgu.0.rcgu.o:(std::sys::unix::fs::File::open_c::h471bc9347f905b01) in archive /Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-493936ddc336b3cf.rlib
>>> referenced by mod.rs:0 (library/std/src/sys/unix/mod.rs:0)
>>> std-493936ddc336b3cf.std.7b49138af54fd575-cgu.0.rcgu.o:(std::sys::unix::fs::File::open_c::h471bc9347f905b01) in archive /Users/aarongriffin/.rustup/toolchains/stable-aarch64-apple-darwin/lib/rustlib/x86_64-unknown-linux-musl/lib/libstd-493936ddc336b3cf.rlib
error: could not compile `zig-repro` (bin "zig-repro") due to previous error
Versions: ziglang: 0.11.0 cargo-zigbuild: 0.17.0 rust: 1.71.1
I'm not sure if this is really the fault of
cargo-zigbuild
but as of ziglang 0.11.0, I get linker errors trying to cross compile tox86_64-unknown-linux-musl
from multiple platforms with code that compiles fine using 0.10.1 (M1 mac and x86_64 linux boxes).Here's a snippet that reproduces the issue
Cross compiling should result in the undefined symbols: