Replies: 2 comments 3 replies
-
No, the sysroot is elsewhere ( I'm not sure what went wrong with zig, as for the attempt to borrow the sysroot from the target, not going to delve into it :3 |
Beta Was this translation helpful? Give feedback.
-
I don't use cross myself, but have plenty of experience with cross-compilation via Zig makes targeting lower glibc (or specific release) pretty straight-forward, but when you should also keep in mind situations where your build will link to libs in it's search path, and that differs from runtime resolving of deps. For example I can build for
In some cases you may want to link to libraries that are not part of the host system, but bundled with your binary for distribution. These can be linked to by having your binary built (or in post via tools like From other information you shared it sounds like you were trying to build static glibc? This is generally discouraged as it's not proper static like musl.
Oh and Zig doesn't support static glibc, it will segfault in earlier releases and fail/error on the current 14 series IIRC, but it is being enabled as a supported option with Zig 15 but not for non-native/custom targets which includes targeting different glibc than system IIRC, |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an
armv7-unknown-linux-gnueabihf
target with a rather old glibc 2.20. So the standard way of cross compiling does not work for me, because the glibc versions provided by the ghcr.io/cross-rs/armv7-unknown-linux-gnueabihf images do not match my target system. So my naive idea was, why not link against the target system itself? I have an image of the target system that I have mounted into the docker image so that I can tell the linker to use it as sysroot. I am not an expert when it comes to cross compiling, so maybe this idea does not work at all. It would be nice, if someone can help me.These are my attempts so far:
Sysroot link attempts
I added these lines to
Cross.toml
in order to mount my sysroot and configuring the linker to use it:Unfortunately I cannot use the environment variable
MY_SYSROOT
in the last line, because it would no be expanded. Off-topic question: Is there a simple solution for that?I noticed that the linker does not use the libc from
/path/to/my/sysroot/lib/libc-2.20.so
(it linked without errors, but the resulting executable has GLIBC links greater 2.20 when examining with readelf). So I explicitly tell the linker to use that version by adding this line inbuild.rs
:I asume that the linker uses libc from my sysroot now, but it still uses a different libpthread that is not compatible. For example I get the linker error:
What is the correct way to tell the linker to only look in my sysroot? Apparently it still looks in
/usr/lib/gcc-cross/arm-linux-gnueabihf
.I also tried to specify the search paths in
build.rs
in addition.Then I get:
libpthread_nonshared.a
is not available on my target system. I am not sure why this happens. Can anyone explain this?Creating new image with correct libc version
I tried to create a new docker image that has the correct libc version. I followed the instructions in the cross-toolchains repository and in this discussion. I did manage to create a new image using these commands:
In the end there was one warning. I am not sure if that can be ignored:
I was able to successfully compile a hello world program (without setting a sysroot for now). But it was using a new libc. And looking into the image I found this file:
/usr/lib32/libc-2.31.so
. Shouldn't that be 2.20?Using zig
Now I tried to specifiy the correct libc version with zig. I added the following to my
Cross.toml
:The sysroot was still set. The program compiled and linked successfully. But I get a core dump when running the executable on the target:
Does anyone have an idea what went wrong?
Using musl target
Using the target
armv7-unknown-linux-musleabihf
works out of the box. However, I am curious why my attempts above do not work. Maybe someone has an idea?Beta Was this translation helpful? Give feedback.
All reactions