"undefined reference to `__stat_time64'" when cross-compiling rust project on musl 1.2.0
The problem is that the MUSL libc that ships with Rust versions up to and including 1.44 is MUSL libc 1.1.X based, not 1.2.0.
When Rust builds libgit2 is also needs to build libgit2-sys, which is C code. When building libgit2-sys it uses the MUSL libc version that you've built and installed yourself with musl-cross-make. This is 1.2.0 by default, which has reworked time_t 32/64
bit support, having a dependency on __stat_time64
and various other similarly named methods (such as __time64
).
However, when Rust is linking your final application it is using the version of MUSL libc shipped with Rust for the x86_64-linux-musl target, which doesn't include that new time_t support, and doesn't have __stat_time64
, __time64
, etc. So the link fails.
Right now you have 2 options:
- Use musl-cross-make to build 1.1.24 of MUSL lib. I'm not 100% what version is included with Rust 1.44. It may be 1.1.22, although from my own testing I found 1.1.24 works just fine (as have you).
- Build your own version of Rust and/or the target liblibc.rlib with your own version of MUSL libc. I've never managed to successfully achieve this myself, although this might be a good place to start if you want to try this.
The general issue of using libc shipped with Rust, instead of a locally provided version, is being worked on, e.g. here.
You could try the instructions listed in https://github.com/richfelker/libcompat_time32:
Add
-Wl,--whole-archive -lcompat_time32 -Wl,--no-whole-archive
to the link command line. Special hacks (like prepending-Wl,
to-lcompat_time32
) may be needed if libtool is intercepting and mangling the command line.