我试图交叉编译一个简单的Rust程序,使用安装了libasound-dev库的Docker容器中的libasound-dev,在Raspberry上用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。我如何告诉货物在哪里寻找这些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容器链接到ARM版本的libasound.so
发布于 2019-07-15 11:12:12
解决方案:
apt-get install libasound-dev -y
apt-get install libasound-dev:armhf -y(如果您只安装了libasound-dev:armhf,它就会抱怨alsa-sys链接器错误。)
alsa依赖项添加到Cargo.toml中:[dependencies]
alsa = { version = "0.2.1", optional = true }
wavy = { path = "./wavy" }alsa-backend中设置Cargo.toml标志:[features]
alsa-backend = ["alsa"]--features "alsa-backend"传递给cargo build --target arm-unknown-linux-gnueabihf (应该应用目标).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版本。)
https://stackoverflow.com/questions/57037550
复制相似问题