Can't run x86_64-unknown-linux-musltoolchain on Centos7

hi, I'm trying to build musl target on centos 7. but seems the cargo on musl toolchain is invalid.. which says libgcc_s.so.1 is invalid, I hava no idea why this error happending.

[root@localhost bin]# pwd
/root/.rustup/toolchains/nightly-2023-06-20-x86_64-unknown-linux-musl/bin


[root@localhost bin]# ./cargo
Error loading shared library libgcc_s.so.1: Exec format error (needed by ./cargo)
Error relocating ./cargo: _Unwind_Resume: symbol not found
Error relocating ./cargo: _Unwind_GetIPInfo: symbol not found
Error relocating ./cargo: _Unwind_GetDataRelBase: symbol not found
Error relocating ./cargo: _Unwind_GetRegionStart: symbol not found
Error relocating ./cargo: _Unwind_SetGR: symbol not found
Error relocating ./cargo: _Unwind_FindEnclosingFunction: symbol not found
Error relocating ./cargo: _Unwind_GetTextRelBase: symbol not found
Error relocating ./cargo: _Unwind_DeleteException: symbol not found
Error relocating ./cargo: _Unwind_RaiseException: symbol not found
Error relocating ./cargo: _Unwind_GetIP: symbol not found
Error relocating ./cargo: _Unwind_Backtrace: symbol not found
Error relocating ./cargo: _Unwind_GetCFA: symbol not found
Error relocating ./cargo: _Unwind_GetLanguageSpecificData: symbol not found
Error relocating ./cargo: _Unwind_SetIP: symbol not found
[root@localhost bin]# file /usr/lib64/libgcc_s.so.1
/usr/lib64/libgcc_s.so.1: symbolic link to `libgcc_s-4.8.5-20150702.so.1'
[root@localhost bin]# file /usr/lib64/libgcc_s-4.8.5-20150702.so.1
/usr/lib64/libgcc_s-4.8.5-20150702.so.1: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=edf51350c7f71496149d064aa8b1441f786df88a, stripped

Your dynamic linker doesn't know where to find libgcc_s.so.1. You can explicitly tell it where to look by setting the LD_LIBRARY_PATH variable, like so:

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib64/ ./cargo

If your libgcc_s shared object wasn't built with musl, you'll probably get a new set of errors. You can download an appropriate shared object from here:

The x86_64-linux-musl-native.tgz tarball should have what you need.

If that works, you can set the LD_LIBRARY_PATH permanently in whatever way is convenient for you.

You can't run a program compiled for dynamically linked musl on a distro based on glibc like CentOS without installing musl on this system too. If you want to build for musl on a glibc based distro you should install rustc compiled for glibc and then use this rustc to compile for musl instead.

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.