Can't compile 32bit on Alpine linux wsl

Been able to compile for 64 bit and can copy it to another linux distro with no issue using cargo b --release commands.

But when compiling for 32bit, I run this:

cargo build --target i686-unknown-linux-gnu --release

And I get this error:

error: linking with `cc` failed: exit status: 1

with a whole bunch of texts, not too sure how to fix this on alpine I think I need to install other building tools but yeah please do advise me.

without the actual error message, I can only guess the errors are saying something like the archtecture of system libraries are not compatible, or cannot find libraries for x86.

to my knowledge, alpine's musl-gcc doesn't enable multlib, and also, you cannot install the musl libc of multiple architectures. so I would say alpine is not ideal to do this kind of cross compiling. you could either:

  1. build the project in a native 32bit alpine distro; or
  2. use a distro that is cross-compiling friendly, like debian; or
  3. try cross-rs: GitHub - cross-rs/cross: “Zero setup” cross compilation and “cross testing” of Rust crates
1 Like

ok so on Windows I installed cross and docker and managed to compile it, however when running this on a 32bit linux operating system I get the following errors:

./updatesql_email_err
./updatesql_email_err: /lib/libc.so.6: version `GLIBC_2.29' not found (required by ./updatesql_email_err)
./updatesql_email_err: /lib/libc.so.6: version `GLIBC_2.9' not found (required by ./updatesql_email_err)
./updatesql_email_err: /lib/libc.so.6: version `GLIBC_2.16' not found (required by ./updatesql_email_err)
./updatesql_email_err: /lib/libc.so.6: version `GLIBC_2.15' not found (required by ./updatesql_email_err)
./updatesql_email_err: /lib/libc.so.6: version `GLIBC_2.28' not found (required by ./updatesql_email_err)
./updatesql_email_err: /lib/libc.so.6: version `GLIBC_2.18' not found (required by ./updatesql_email_err)

so some linking issues I have, is there a way to statically link glibc or something?

Statically linking glibc is a bad idea. If anything it makes the program less portable due to certain paths getting hard coded in the final executable that differ between distros. It also breaks certain functionality of glibc due to said functionality requiring dynamic linking support. Musl is easier to statically link.

In your case it seems like you have glibc 2.8 or older. Glibc 2.9 was released in 2008. If your kernel is just as old, rust won't work with it even if you get a working libc. Rust needs 4.1 or older as kernel version which is from 2015. Can you run /lib/libc.so.6 (or if that doesn't work with glibc versions this old, /lib/ld-linux.so.2) to get the version of glibc you have on your system and uname -r to get the kernel version to confirm that you have a too old system? (All commands should be run on the target system, not the system you used to build)

1 Like

Dumb question but should I then statically link Musl into my rust binary for a GNU/Linux 32bit operating system, that would work, right?

What would running this do?

i686-unknown-linux-musl seems to work if I use this actually this is the solution, thanks

Alpine Linux doesn’t have glibc at all. It is built on musl instead of GNU libc. So using the musl targets instead of the gnu ones is the correct solution.

It prints a message which includes the version of glibc as well as some other information about the dynamic linker.

I meant the distro that I wanted to put the executable on was 32bit GNU/Linux but I had alpine wsl on my windows computer so yeah wanted to figure out how to compile it for that but yeah it works now.

Right I see, I guess that doesn't matter anymore as I got it working now.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.