Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NDK 23 beta: Build fails with unable to find library -lgcc #22

Closed
zskamljic opened this issue Jun 28, 2021 · 11 comments · Fixed by #67
Closed

NDK 23 beta: Build fails with unable to find library -lgcc #22

zskamljic opened this issue Jun 28, 2021 · 11 comments · Fixed by #67
Labels
bug Something isn't working has-workaround

Comments

@zskamljic
Copy link

I'm trying to build a new project, however when running the command cargo ndk -t aarch64-linux-android -o ./jniLibs build --release, but I end up with an error;

error: linking with `/home/<user>/Android/Sdk/ndk/23.0.7421159/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang` failed: exit status: 1
  |
  = note: ld: error: unable to find library -lgcc
          clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
@bbqsrc
Copy link
Owner

bbqsrc commented Jun 28, 2021

Does it work if you use ndk 22.x or lower?

@zskamljic
Copy link
Author

Yes, it seems that way the .so file is created

@bbqsrc bbqsrc changed the title Build fails with unable to find library -lgcc NDK 23 beta: Build fails with unable to find library -lgcc Jun 29, 2021
@bbqsrc bbqsrc added the bug Something isn't working label Jun 29, 2021
@bbqsrc
Copy link
Owner

bbqsrc commented Jul 1, 2021

So, NDK 23 removes libgcc entirely. Rust relies on this for providing missing builtins on Android.

rust-lang/rust#85806 should fix it.

@bbqsrc
Copy link
Owner

bbqsrc commented Aug 3, 2021

This seems to still only work with nightly. To use aarch64 builds as an example, this will work:

cargo +nightly ndk -t arm64-v8a build -Zbuild-std

The problem seems to be the Rust CI builds for Android still use an older NDK or something similar that causes it to require libgcc. If you build your own std, no problem.

@tux3

This comment has been minimized.

@bbqsrc
Copy link
Owner

bbqsrc commented Sep 10, 2021

@tux3 this is a separate issue, please create one and report this there 😄

@acrrd
Copy link

acrrd commented Apr 26, 2022

Do you think that porting this workaround will be suitable for cargo ndk?
https://github.com/rust-windowing/android-ndk-rs/blob/f24606cc840af2f97f0daebe1e2e7cd3aca52287/cargo-apk/src/apk.rs#L184

@bbqsrc
Copy link
Owner

bbqsrc commented Apr 26, 2022

If somebody wishes to do so.

@Fernthedev
Copy link

Fernthedev commented Jun 6, 2022

I'd like to mention that the workaround named above (building with std) does not work in my situation. I am using NDK R24 if that requires mentioning
I still get ld: error: unable to find library -lgcc using this command invocation:

rustup target install aarch64-linux-android
rustup component add rust-src --toolchain nightly --target aarch64-linux-android
cargo +nightly ndk -t arm64-v8a -o target/release build -Zbuild-std --verbose --release

If anyone would like to test this very specific scenario, the project is over here and shouldn't require extensive setup configurations.

Note:

  • I have not tested with other NDK versions
  • I have not tested other rust projects

Am I missing something? Feel free to call me out on it

Update:
Tested NDK R23c and still does not work

@Qinruiy
Copy link

Qinruiy commented Jun 14, 2022

I'd like to mention that the workaround named above (building with std) does not work in my situation. I am using NDK R24 if that requires mentioning I still get ld: error: unable to find library -lgcc using this command invocation:

rustup target install aarch64-linux-android
rustup component add rust-src --toolchain nightly --target aarch64-linux-android
cargo +nightly ndk -t arm64-v8a -o target/release build -Zbuild-std --verbose --release

If anyone would like to test this very specific scenario, the project is over here and shouldn't require extensive setup configurations.

Note:

  • I have not tested with other NDK versions
  • I have not tested other rust projects

Am I missing something? Feel free to call me out on it

Update: Tested NDK R23c and still does not work

rust-lang/rust#85806 (comment)

create 4 text files named libgcc.a in the same folders with this contents
it works on ndk 24.0.8215888

tharvik added a commit to c4dt/lightarti-rest that referenced this issue Jul 20, 2022
tharvik added a commit to c4dt/lightarti-rest that referenced this issue Jul 20, 2022
tharvik added a commit to c4dt/lightarti-rest that referenced this issue Jul 20, 2022
tharvik added a commit to c4dt/lightarti-rest that referenced this issue Jul 20, 2022
tharvik added a commit to c4dt/lightarti-rest that referenced this issue Jul 20, 2022
tharvik added a commit to c4dt/lightarti-rest that referenced this issue Jul 20, 2022
rib added a commit to rib/cargo-ndk that referenced this issue Jul 23, 2022
libgcc was removed from NDK v23 which breaks Rust builds against
pre-built standard libraries that were linked against libgcc
instead of libunwind.

As a workaround this ensures that there is a libgcc.a in the
library search paths which is a linker script that will redirect
to link with libunwind instead.

The libgcc.a linker script is created under:

 target/cargo-ndk/libgcc_workaround/libgcc.a

Fixes: bbqsrc#22
rib added a commit to rib/cargo-ndk that referenced this issue Jul 24, 2022
libgcc was removed from NDK v23 which breaks Rust builds against
pre-built standard libraries that were linked against libgcc
instead of libunwind.

As a workaround this ensures that there is a libgcc.a in the
library search paths which is a linker script that will redirect
to link with libunwind instead.

The libgcc.a linker script is created under:

 target/cargo-ndk/libgcc-workaround/libgcc.a

Fixes: bbqsrc#22
@rib
Copy link
Contributor

rib commented Jul 24, 2022

Do you think that porting this workaround will be suitable for cargo ndk? https://github.com/rust-windowing/android-ndk-rs/blob/f24606cc840af2f97f0daebe1e2e7cd3aca52287/cargo-apk/src/apk.rs#L184

For reference the PR #67 I recently opened effectively supports this same workaround.

bbqsrc pushed a commit that referenced this issue Jul 24, 2022
libgcc was removed from NDK v23 which breaks Rust builds against
pre-built standard libraries that were linked against libgcc
instead of libunwind.

As a workaround this ensures that there is a libgcc.a in the
library search paths which is a linker script that will redirect
to link with libunwind instead.

The libgcc.a linker script is created under:

 target/cargo-ndk/libgcc-workaround/libgcc.a

Fixes: #22
ineiti pushed a commit to c4dt/lightarti-rest that referenced this issue Aug 2, 2022
tharvik added a commit to c4dt/lightarti-rest that referenced this issue Aug 3, 2022
tharvik added a commit to c4dt/lightarti-rest that referenced this issue Aug 3, 2022
tharvik added a commit to c4dt/lightarti-rest that referenced this issue Aug 3, 2022
tharvik added a commit to c4dt/lightarti-rest that referenced this issue Aug 3, 2022
ineiti pushed a commit to c4dt/lightarti-rest that referenced this issue Aug 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working has-workaround
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants