Can't successfully cross-compile `librespot` for arm-unknown-linux-musleabihf on ubuntu 22.04
Question: Can't successfully cross-compile ‘librespot’ for arm-unknown-linux-musleabihf on ubuntu 22.04.
Error Log on run cargo build:
......
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `stderr@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `nanosleep@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `setsockopt@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `__ctype_b_loc@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `getgrnam_r@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `sigaction@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `regcomp@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `semop@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `sigemptyset@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `connect@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `versionsort@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `regexec@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `waitpid@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `dladdr1@GLIBC_2.34'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `__sprintf_chk@GLIBC_2.4'
/opt/arm-linux-musleabihf-cross/bin/../lib/gcc/arm-linux-musleabihf/11.2.1/../../../../arm-linux-musleabihf/bin/ld: /usr/lib/arm-linux-gnueabihf/libasound.so: undefined reference to `__errno_location@GLIBC_2.4'
collect2: error: ld returned 1 exit status
= note: some extern functions couldn't be found; some native libraries may need to be installed or have their path specified
= note: use the -l flag to specify native libraries to link
= 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#cargorustc-link-libkindname)
cargo build Command:
RUSTFLAGS="-C link-args=-Wl,-rpath-link,/lib -C target-feature=-crt-static" PKG_CONFIG_PATH_arm_unknown_linux_musleabihf="/usr/lib/arm-linux-gnueabihf/pkgconfig" PKG_CONFIG_ALLOW_CROSS=1 cargo build --release --target arm-unknown-linux-musleabihf
Full Log:
https://pastebin.com/yU2UTiK1
Environment:
- OS: Ubuntu 22.04 LTS
- Platform: VirtualBox (8GB RAM and 50GB disk space. Dont worry about the platform!)
- Language: Chinese
- Installed packages: crossbuild-essential-armhf, libasound2-dev:armhf(and other dependencies)
- Target Platform: Nokia 800 Tough (KaiOS 2.5.x Linux3.10 Alsa-Supported Busybox-Supported Root-Supported NO-glibc-supported)
- Target on
cargo --target: arm-unknown-linux-musleabihf (must using musl because usingguneabihfcant run on target device. )
Action that I did:
- Install the rustup with the Chinese mirror server (run as root):
export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup
curl --proto '=https' --tlsv1.3 https://sh.rustup.rs -sSf | sh
-
Downloaded the
muslcompilation toolchain from musl.cc, versioncrossarm-linux-musleabihf,and added the toolchain path to the PATH:https://musl.cc/arm-linux-musleabihf-cross.tgzPATH is:/opt/arm-linux-musleabihf/bin -
Add armhf support to dpkg and change armhf software source to "China Tsinghua University open source software mirror":
/etc/apt/sources.list
#deb cdrom:[Ubuntu 22.04.2 LTS _Jammy Jellyfish_ - Release amd64 (20230223)]/ jammy main restricted
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates main restricted
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team. Also, please note that software in universe WILL NOT receive any
## review or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy universe
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates universe
## N.B. software from this repository is ENTIRELY UNSUPPORTED by the Ubuntu
## team, and may not be under a free licence. Please satisfy yourself as to
## your rights to use the software. Also, please note that software in
## multiverse WILL NOT receive any review or updates from the Ubuntu
## security team.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy multiverse
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-updates multiverse
## N.B. software from this repository may not have been tested as
## extensively as that contained in the main release, although it includes
## newer versions of some applications which may provide useful features.
## Also, please note that software in backports WILL NOT receive any review
## or updates from the Ubuntu security team.
deb http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src http://cn.archive.ubuntu.com/ubuntu/ jammy-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu jammy-security main restricted
# deb-src http://security.ubuntu.com/ubuntu jammy-security main restricted
deb http://security.ubuntu.com/ubuntu jammy-security universe
# deb-src http://security.ubuntu.com/ubuntu jammy-security universe
deb http://security.ubuntu.com/ubuntu jammy-security multiverse
# deb-src http://security.ubuntu.com/ubuntu jammy-security multiverse
# This system was installed using small removable media
# (e.g. netinst, live or single CD). The matching "deb cdrom"
# entries were disabled at the end of the installation process.
# For information about how to configure apt package sources,
# see the sources.list(5) manual.
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb [arch=armhf,arm64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy main restricted universe multiverse
deb [arch=armhf,arm64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-updates main restricted universe multiverse
deb [arch=armhf,arm64] https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-backports main restricted universe multiverse
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-security main restricted universe multiverse
deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
# deb-src http://ports.ubuntu.com/ubuntu-ports/ jammy-security main restricted universe multiverse
# 预发布软件源,不建议启用
# deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse
# # deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu-ports/ jammy-proposed main restricted universe multiverse
- Install crossbuild-essential-armhf, libasound2-dev:armhf(run as root):
apt update
apt install crossbuild-essential-armhf libasound2-dev:armhf
-
cargo build - Error.
Additional context The dockerfile provided by repo does not compile to musl. my attempts to use rust-musl-cross and install the environment manually also failed, so I tried to compile it manually myself instead of docker, if you have any good ideas please let me know. I will try to compile on Pi4 on July 4, 2023 at +8 PM GMT.
So your compilation fails when linking with libasound. In my experience, linking to system binaries is the most painful thing when cross-compiling rust. As a workaround/test you could try adding the flag --no-default-features to cargo build so that the default audio backend rodio-backend doesn't get compiled. Then you would only have a stdout/pipe audio device which you propably could just pipe to aplay.
Hello @BliemHax, if you are still interested, this might be of some help: https://github.com/librespot-org/librespot/pull/1263 What makes it work is using ubuntu 18.04 and fixing C/openssl/sound library links.