在 x86_64 上将 Rust 交叉编译为 aarch64 时出现错误“对 getauxval 的未定义引用”

问题描述 投票:0回答:0

我正在尝试为两个 OpenWRT 路由器构建 Rust 应用程序。一个在ramips(mipsel)平台上,另一个在rockchip(aarch64)平台上。

我很好地完成了 mipsel 的交叉编译,但由于错误消息

undefined reference to 
getauxval'` 而被 aarch64 阻止。详情请见下文。

(...)
-linux-musl/lib/self-contained" "-o" "/tmp/hello-reqwest/target/aarch64-unknown-linux-musl/debug/deps/hello_reqwest-4e5be7f0a2aebac1" "-Wl,--gc-sections" "-static" "-no-pie" "-Wl,-zrelro,-znow" "-nodefaultlibs" "/home/janvier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtend.o" "/home/janvier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/self-contained/crtn.o"
  = note: /home/janvier/toolchain/toolchain-aarch64_generic_gcc-11.2.0_musl/bin/../lib/gcc/aarch64-openwrt-linux-musl/11.2.0/../../../../aarch64-openwrt-linux-musl/bin/ld: /home/janvier/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/aarch64-unknown-linux-musl/lib/libcompiler_builtins-0a28d23d76fcec1d.rlib(cpu_model.o): in function `init_have_lse_atomics':
          /cargo/registry/src/github.com-1ecc6299db9ec823/compiler_builtins-0.1.85/./lib/builtins/cpu_model.c:829: undefined reference to `getauxval'
          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)

error: could not compile `hello-reqwest` due to previous error

main.rs

use std::error::Error;
use reqwest::Client;

#[tokio::main]
async fn main() -> Result<(), Box<dyn Error>> {
    let client = Client::new();
    let response = client.get("https://www.example.com").send().await?;
    let body = response.text().await?;
    println!("Body:\n{}", body);
    Ok(())
}

Cargo.toml

[package]
name = "hello-reqwest"
version = "0.1.0"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
reqwest = "0.11.16"
tokio = { version = "1.27.0", features = ["full"] }
openssl = { version = "0.10.50", features = ["vendored"] }

~/.cargo/config.toml

[target.aarch64-unknown-linux-musl]
linker = "/home/janvier/openwrt-sdk-22.03.2/rockchip/staging_dir/toolchain-aarch64_generic_gcc-11.2.0_musl/bin/aarch64-openwrt-linux-musl-gcc"

[target.mipsel-unknown-linux-musl]
linker = "/home/janvier/openwrt-sdk-22.03.2/ramips/staging_dir/toolchain-mipsel_24kc_gcc-11.2.0_musl/bin/mipsel-openwrt-linux-musl-gcc"

代码和配置可以很好地交叉编译为 mipsel,但无法 aarch64。

有人知道如何解决这个问题吗?

rust cross-compiling arm64 openwrt toolchain
© www.soinside.com 2019 - 2024. All rights reserved.