【问题标题】:How do I fix "ld: error: unable to find library -lgcc" when cross-compiling rust to android?将rust交叉编译到android时如何修复“ld:错误:无法找到库-lgcc”?
【发布时间】:2021-10-22 16:20:15
【问题描述】:

我正在尝试让 rust 在 android 上运行。但是,当我尝试交叉编译到 android 时,出现以下链接错误:

$ cargo build --target=arm-linux-androideabi
   Compiling <project> v0.1.0 (<project>)
error: linking with `/opt/android-sdk/ndk/23.0.7599858/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi31-clang` failed: exit status: 1

(very long toolchain command from cargo)

ld: error: unable to find library -lgcc
          clang-12: error: linker command failed with exit code 1 (use -v to see invocation)

我已经安装了ndk并将.cargo/config中的链接器更改为android clang链接器。我还尝试了具有相同结果的独立工具链。我使用的指南如下:https://mozilla.github.io/firefox-browser-architecture/experiments/2017-09-21-rust-on-android.html

使用crate-type = ["rlib"] 而不是crate-type = ["cdylib"] 时交叉编译确实有效,但我需要.so 文件而不是.rlib 文件。

如果相关,我正在使用 Manjaro Linux。

【问题讨论】:

    标签: linux rust android-ndk rust-cargo


    【解决方案1】:

    更新:

    我发现了以下拉取请求:https://github.com/rust-lang/rust/pull/85806 切换到 ndk22 后它起作用了。我还没有尝试过拉取请求是否解决了问题(可能会)。

    【讨论】:

    • 该 PR 看起来像修复程序。您是否正在运行足够新的 rust 版本?如果 PR 还不够,您需要提交一个防锈漏洞。
    • 我必须等到我可以将自己的答案标记为解决方案。
    • 我有最新的 Rust,这个问题正在发生在我身上。切换到 r22b 也为我解决了这个问题。
    猜你喜欢
    • 1970-01-01
    • 2017-11-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-14
    • 2013-07-17
    • 2016-12-12
    • 2016-10-28
    • 2012-03-20
    相关资源
    最近更新 更多