Docker 交叉编译ARM的Rust程序时的ALSA链接

Docker 交叉编译ARM的Rust程序时的ALSA链接,docker,rust,arm,raspbian,alsa,Docker,Rust,Arm,Raspbian,Alsa,我正在尝试交叉编译一个简单的Rust程序,使用安装了libasound dev库的Docker容器内部的,在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 -las

我正在尝试交叉编译一个简单的Rust程序,使用安装了
libasound dev
库的Docker容器内部的,在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”
动态链接asound库。如何告诉Cargo在哪里查找这些ALSA库

更新:我将以下内容添加到我的Cargo.toml文件中,并将
--功能“alsa后端”
添加到我的
货物构建
命令中,该命令似乎已经推进了构建:

[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
好的,它链接到了libasound.so的x86_64版本。我在Docker容器中键入了
dpkg-L libasound dev
,实际上,它列出了
/usr/lib/x86_64-linux-gnu/libasound.so
,而不是ARM版本

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

解决方案:
  • 将libasound dev的armhf版本安装到Raspbian docker映像中:
  • (如果只安装
    libasound dev:armhf
    ,它会抱怨
    alsa sys
    链接器错误。)

  • alsa
    依赖项添加到Cargo.toml:
  • 在Cargo.toml中设置alsa后端的
    flag:
  • 将功能“alsa后端”传递到货物构建——目标arm未知linux gnueabihf(应应用目标)

  • 告诉rustc在
    .cargo/config
    中使用armhf版本:


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

    感谢您分享解决方案!
    apt-get install libasound-dev -y
    apt-get install libasound-dev:armhf -y
    
    [dependencies]
    alsa = { version = "0.2.1", optional = true }
    wavy = { path = "./wavy" }
    
    [features]
    alsa-backend = ["alsa"]
    
    [build]
    
    [target.arm-unknown-linux-gnueabihf.libasound]
    linker = "arm-linux-gnueabihf-gcc"
    rustc-link-lib = ["libasound"]
    rustc-link-search = ["/usr/lib/arm-linux-gnueabihf"]