Hey,
I'm trying to build a static binary on an Alpine docker container. I use the environment variable RUSTFLAGS
to set -C target-feature=+crt-static
and build by cargo build --release --no-default-features --features with-dns-sd --target x86_64-unknown-linux-musl
but my build failed with
...
-Wl,--gc-sections" "-static-pie" "-Wl,-z,relro,-z,now" "-Wl,-O1" "-nodefaultlibs" "/usr/local/rustup/toolchains/stable-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtendS.o" "/usr/local/rustup/toolchains/stable-x86_64-unknown-linux-musl/lib/rustlib/x86_64-unknown-linux-musl/lib/self-contained/crtn.o"
#9 1223.3 = note: /usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libdns_sd.a(libdns_sd_la-compat.o): in function `query_resolver_callback':
#9 1223.3 compat.c:(.text+0x24c): undefined reference to `avahi_client_errno'
#9 1223.3 /usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libdns_sd.a(libdns_sd_la-compat.o): in function `reg_create_service':
#9 1223.3 compat.c:(.text+0x3f6): undefined reference to `avahi_entry_group_add_service_strlst'
#9 1223.3 /usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: compat.c:(.text+0x43e): undefined reference to `avahi_entry_group_add_service_subtype'
#9 1223.3 /usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: compat.c:(.text+0x450): undefined reference to `avahi_entry_group_commit'
#9 1223.3 /usr/lib/gcc/x86_64-alpine-linux-musl/13.2.1/../../../../x86_64-alpine-linux-musl/bin/ld: /usr/lib/libdns_sd.a(libdns_sd_la-compat.o): in function `thread_func':
#9 1223.3 compat.c:(.text+0x575): undefined reference to `avahi_simple_poll_run'
...
#9 1223.3 collect2: error: ld returned 1 exit status
#9 1223.3
#9 1223.3 = note: some `extern` functions couldn't be found; some native libraries may need to be installed or have their path specified
#9 1223.3 = note: use the `-l` flag to specify native libraries to link
#9 1223.3 = note: use the `cargo:rustc-link-lib` directive to specify the native libraries to link with Cargo (see https://doc.rust-lang.org/cargo/reference/build-scripts.html#rustc-link-lib)
I understand that the linker failed to use/locate /usr/lib/libdns_sd.a
. I tried various combinations of
"-C target-feature=+crt-static -C default-linker-libraries=yes"
"-C target-feature=+crt-static -l /usr/lib/libdns_sd.a"
"-C target-feature=+crt-static -L /usr/lib/"
"-C target-feature=+crt-static -C link-args=-Wl,-rpath,/usr/lib/
But none worked.
Within the source, an extern crate dns_sd
is used which uses pkg_config::find_library("avahi-compat-libdns_sd").unwrap();
to locate the library.
Any ideas how to get the build working?
Thanks.