Hello folks,
I'm attempting to cross-compile a Rust project using the ort crate for an NXP embedded target, specifically armv7ahf-neon-poky-linux-gnueabi
. Since this exact target isn't directly supported by Rust's cross-compilation configurations, I'm using armv7-unknown-linux-gnueabi
as a close approximation, with adjustments made via rustflags to match the target's specific architecture and ABI.
Issue
The build process fails during the linking stage with numerous "cannot find" errors, indicating that the linker cannot locate essential libraries and object files. This suggests a potential misconfiguration in the linker's search paths or a mismatch between the build environment and the target SDK.
Here is the build config
Environment
- Target: armv7ahf-neon-poky-linux-gnueabi (NXP Embedded System)
- Host: x86_64 Linux
- SDK: Poky SDK for the target architecture
- Rust Version: 1.85.1 (4eb161250 2025-03-15)
- Cargo Version: cargo 1.85.1 (d73d2caf9 2024-12-31)
- ort Version: 1.16.2
- Toolchain: arm-poky-linux-gnueabi-gcc, arm-poky-linux-gnueabi-ar
Configurations
-
~/.cargo/config.toml
[target.armv7-unknown-linux-gnueabi] linker = "arm-poky-linux-gnueabi-gcc" ar = "arm-poky-linux-gnueabi-ar" rustflags = [ "-C", "link-arg=--sysroot=/data/sdk/sysroots/armv7ahf-neon-poky-linux-gnueabi", "-C", "link-arg=-march=armv7-a", "-C", "link-arg=-marm", "-C", "link-arg=-mfpu=neon", "-C", "link-arg=-mfloat-abi=hard", "-Clink-args=-Wl,-rpath,\\$ORIGIN", ]
-
The
Cargo.toml
:[package] name = "sed-rs" version = "0.1.0" edition = "2021" [dependencies] ort = { version = "1.16.2", features = [] } ndarray = "0.15.6" tracing-subscriber = { version = "0.3", default-features = false, features = [ "env-filter", "fmt" ] } symphonia = { version = "0.5.4", features = ["mp3", "wav"] } clap = { version = "4.5.32", features = ["derive"] } # cpal ={ version = "0.15.3"} hound = "3.5.1" rubato ="0.16.1" [profile.dev] rpath = true [profile.release] rpath = true
-
Build Command
source /data/sdk/environment-setup-armv7ahf-neon-poky-linux-gnueabi export CC_x86_64_unknown_linux_gnu=gcc export ORT_STRATEGY=system export ORT_LIB_LOCATION=/data/sdk/sysroots/armv7ahf-neon-poky-linux-gnueabi/usr/lib/libonnxruntime.so export ORT_INCLUDE_DIR=/data/sdk/sysroots/armv7ahf-neon-poky-linux-gnueabi/usr/include export RUSTFLAGS="-C link-arg=--sysroot=/data/sdk/sysroots/armv7ahf-neon-poky-linux-gnueabi -C link-arg=-L/data/sdk/sysroots/armv7ahf-neon-poky-linux-gnueabi/usr/lib -C link-arg=-L/data/sdk/sysroots/armv7ahf-neon-poky-linux-gnueabi/usr/lib/arm-poky-linux-gnueabi/12.2.0 -C link-arg=-L/data/sdk/sysroots/armv7ahf-neon-poky-linux-gnueabi/lib link-arg=-Wl,-v" RUSTFLAGS="-C link-arg=-v" cargo build --target=armv7-unknown-linux-gnueabi -v "$@"
I got some links as follows:
Error Messages
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find Scrt1.o: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find crti.o: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find crtbeginS.o: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find -lstdc++: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find -lonnxruntime: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find -lgcc_s: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find -lutil: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find -lrt: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find -lpthread: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find -lm: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find -ldl: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find -lc: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find crtendS.o: No such file or directory
/data/sdk/sysroots/x86_64-pokysdk-linux/usr/libexec/arm-poky-linux-gnueabi/gcc/arm-poky-linux-gnueabi/12.2.0/ld: cannot find crtn.o: No such file or directory
collect2: error: ld returned 1 exit status
error: could not compile `sed-rs` (bin "sed-rs") due to 1 previous error
Does anyone have some idea if it is related to my config or the SDK?