【问题标题】:ALSA linking when cross-compiling Rust program for ARM为 ARM 交叉编译 Rust 程序时的 ALSA 链接
【发布时间】:2019-11-24 00:38:33
【问题描述】:

我正在尝试交叉编译一个简单的 Rust 程序,以便在安装了 libasound-dev 库的 Docker 容器内使用 wavy crate 在 Raspberry Pi Zero 上使用 ALSA 驱动程序录制声音。但是,链接器抱怨:

 note: /opt/gcc-linaro-arm-linux-gnueabihf-raspbian-x64/bin/../lib/gcc/arm-linux-gnueabihf/4.8.3/../../../../arm-linux-gnueabihf/bin/ld: cannot find -lasound
          collect2: error: ld returned 1 exit status

Cargo 似乎要求 rustc 使用参数 -Bdynamic" "-lasound" 动态链接到健全的库。我如何告诉 Cargo 在哪里可以找到这些 ALSA 库?

更新:我将以下内容添加到我的 Cargo.toml 文件中,并将 --features "alsa-backend" 添加到我的 cargo build 命令中,这似乎已经推进了构建:

[features]
alsa-backend = ["alsa"]

[dependencies]
alsa            = { version = "0.2.1", optional = true }

现在抛出:

note: /usr/lib/x86_64-linux-gnu/libasound.so: file not recognized: File format not recognized
          collect2: error: ld returned 1 exit status

好的,所以它链接到 x86_64 版本的 libasound.so。我在我的 Docker 容器中输入了 dpkg -L libasound-dev,实际上,它列出了 /usr/lib/x86_64-linux-gnu/libasound.so 而不是 ARM 版本。

如何让 Raspbian Docker 容器链接到 ARM 版本的 libasound.so

【问题讨论】:

    标签: docker rust arm raspbian alsa


    【解决方案1】:

    解决方案:

    1. 将 armhf 版本的 libasound-dev 安装到您的 Raspbian docker 映像中:
    apt-get install libasound-dev -y
    apt-get install libasound-dev:armhf -y
    

    (如果只安装libasound-dev:armhf,会报alsa-sys链接器错误。)

    1. 在 Cargo.toml 中添加 alsa 依赖:
    [dependencies]
    alsa = { version = "0.2.1", optional = true }
    wavy = { path = "./wavy" }
    
    1. 在 Cargo.toml 中设置 alsa-backend 标志:
    [features]
    alsa-backend = ["alsa"]
    
    1. --features "alsa-backend" 传递给cargo build --target arm-unknown-linux-gnueabihf(应应用目标)

    2. 告诉 rustc 使用 .cargo/config 中的 armhf 版本:

    [build]
    
    [target.arm-unknown-linux-gnueabihf.libasound]
    linker = "arm-linux-gnueabihf-gcc"
    rustc-link-lib = ["libasound"]
    rustc-link-search = ["/usr/lib/arm-linux-gnueabihf"]
    

    (根据链接的顺序,它可能会尝试使用 x86 版本而不是 armhf 版本。)

    【讨论】:

    • 感谢您分享解决方案!
    猜你喜欢
    • 1970-01-01
    • 2016-07-11
    • 2023-02-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-03
    • 2021-02-26
    • 2018-11-30
    相关资源
    最近更新 更多