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

Improper target flag for newer NDKs #1440

Open
GglLfr opened this issue Mar 20, 2025 · 5 comments
Open

Improper target flag for newer NDKs #1440

GglLfr opened this issue Mar 20, 2025 · 5 comments
Labels
bug O-android Operating system: Android

Comments

@GglLfr
Copy link

GglLfr commented Mar 20, 2025

cc's auto-detection for NDK supplies --target arm-linux-android instead of something like --target armv7a-linux-androideabi35, causing the wrong (and non-existent) sysroot to be used and leading to this error:

ld.lld: error: cannot open crtbegin_dynamic.o: No such file or directory
ld.lld: error: cannot open crtend_android.o: No such file or directory
clang: error: linker command failed with exit code 1 (use -v to see invocation)
@NobodyXu
Copy link
Collaborator

We use the information extracted from rustc, so I suppose maybe rustc has the wrong information?

@GglLfr
Copy link
Author

GglLfr commented Mar 20, 2025

Actually, it might've been caused by these lines. armv7a-linux-androideabi16-clang doesn't exist at all in my installation (that I obtained using sdkmanager --install "ndk;29.0.13113456"). armv7a-linux-androideabi21-clang does exist, however.

@GglLfr
Copy link
Author

GglLfr commented Mar 20, 2025

Manually setting CC=aarch64-linux-android35-clang.cmd and CXX=aarch64-linux-android35-clang++.cmd makes the project compile. I'll create a minimum reproducible example soon.

@madsmtm madsmtm added bug O-android Operating system: Android labels Mar 20, 2025
@GglLfr
Copy link
Author

GglLfr commented Mar 21, 2025

I've pushed this example, which is just a stripped version of android-activity; the error was different, but caused by wrong sysroots nonetheless:

warning: [email protected]: Compiler family detection failed due to error: ToolNotFound: failed to find tool "aarch64-linux-android-clang++": program not found (see https://docs.rs/cc/latest/cc/#compile-time-requirements for help)
warning: [email protected]: In file included from csrc/game-activity/GameActivity.cpp:38:
warning: [email protected]: In file included from C:/Android/ndk/29.0.13113456/toolchains/llvm/prebuilt/windows-x86_64/bin/../sysroot/usr/include/c++/v1/mutex:191:
warning: [email protected]: C:/Android/ndk/29.0.13113456/toolchains/llvm/prebuilt/windows-x86_64/bin/../sysroot/usr/include/c++/v1/__condition_variable/condition_variable.h:226:14: error: use of undeclared identifier 'pthread_cond_clockwait'
warning: [email protected]:   226 |   int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts);
warning: [email protected]:       |              ^
warning: [email protected]: 1 error generated.
error: failed to run custom build command for `android-test v0.1.0 (C:\Users\glenn\android-test)`

Caused by:
  process didn't exit successfully: `C:\Users\glenn\android-test\target\debug\build\android-test-a8da2f7d96533915\build-script-build` (exit code: 1)
  --- stdout
  cargo::rerun-if-changed=csrc/game-activity/GameActivity.h
  cargo::rerun-if-changed=csrc/game-activity/GameActivity.cpp
  cargo::rerun-if-changed=csrc/game-activity/GameActivityEvents.h
  cargo::rerun-if-changed=csrc/game-activity/GameActivityEvents.cpp
  cargo::rerun-if-changed=csrc/game-activity/GameActivityLog.h
  OUT_DIR = Some(C:\Users\glenn\android-test\target\aarch64-linux-android\debug\build\android-test-d0a1e40c764ebdc4\out)
  OPT_LEVEL = Some(0)
  TARGET = Some(aarch64-linux-android)
  HOST = Some(x86_64-pc-windows-msvc)
  cargo:rerun-if-env-changed=CXX_aarch64-linux-android
  CXX_aarch64-linux-android = None
  cargo:rerun-if-env-changed=CXX_aarch64_linux_android
  CXX_aarch64_linux_android = None
  cargo:rerun-if-env-changed=TARGET_CXX
  TARGET_CXX = None
  cargo:rerun-if-env-changed=CXX
  CXX = None
  cargo:rerun-if-env-changed=CC_ENABLE_DEBUG_OUTPUT
  cargo:warning=Compiler family detection failed due to error: ToolNotFound: failed to find tool "aarch64-linux-android-clang++": program not found (see https://docs.rs/cc/latest/cc/#compile-time-requirements for help)
  RUSTC_WRAPPER = None
  cargo:rerun-if-env-changed=CRATE_CC_NO_DEFAULTS
  CRATE_CC_NO_DEFAULTS = None
  DEBUG = Some(false)
  cargo:rerun-if-env-changed=CXXFLAGS
  CXXFLAGS = None
  cargo:rerun-if-env-changed=TARGET_CXXFLAGS
  TARGET_CXXFLAGS = None
  cargo:rerun-if-env-changed=CXXFLAGS_aarch64_linux_android
  CXXFLAGS_aarch64_linux_android = None
  cargo:rerun-if-env-changed=CXXFLAGS_aarch64-linux-android
  CXXFLAGS_aarch64-linux-android = None
  CARGO_ENCODED_RUSTFLAGS = Some()
  cargo:warning=In file included from csrc/game-activity/GameActivity.cpp:38:
  cargo:warning=In file included from C:/Android/ndk/29.0.13113456/toolchains/llvm/prebuilt/windows-x86_64/bin/../sysroot/usr/include/c++/v1/mutex:191:
  cargo:warning=C:/Android/ndk/29.0.13113456/toolchains/llvm/prebuilt/windows-x86_64/bin/../sysroot/usr/include/c++/v1/__condition_variable/condition_variable.h:226:14: error: use of undeclared identifier 'pthread_cond_clockwait'
  cargo:warning=  226 |   int __ec = pthread_cond_clockwait(&__cv_, __lk.mutex()->native_handle(), CLOCK_MONOTONIC, &__ts);
  cargo:warning=      |              ^
  cargo:warning=1 error generated.

  --- stderr


  error occurred in cc-rs: command did not execute successfully (status code exit code: 1): "clang++.exe" "--target=aarch64-linux-android" "-O0" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-I" "csrc" "-Wall" "-o" "C:\\Users\\glenn\\android-test\\target\\aarch64-linux-android\\debug\\build\\android-test-d0a1e40c764ebdc4\\out\\4288ea7fee210c9f-GameActivity.o" "-c" "csrc/game-activity/GameActivity.cpp"

I tried running this code separately:

"clang++.exe" "--target=aarch64-linux-android" "-O0" "-DANDROID" "-ffunction-sections" "-fdata-sections" "-fPIC" "-I" "csrc" "-Wall" "-o" "C:\\Users\\glenn\\android-test\\target\\aarch64-linux-android\\debug\\build\\android-test-d0a1e40c764ebdc4\\out\\4288ea7fee210c9f-GameActivity.o" "-c" "csrc/game-activity/GameActivity.cpp"

Which does throw that undefined pthread_cond_clockwait error. I tried running it again, except I changed --target=aarch64-linux-android to --target=aarch64-linux-android35, and it compiles.

This creates another issue though: How exactly do we pass the intended Android API level to cc? Right now it seems to be hardcoded to API level 21 (and 16 for armv7-linux-androideabi).

@GglLfr
Copy link
Author

GglLfr commented Mar 21, 2025

Manually setting .flag("--target=aarch64-linux-android35") does make compiling with cargo build --target aarch64-linux-android work, but it seems quite hacky 😓

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug O-android Operating system: Android
Projects
None yet
Development

No branches or pull requests

3 participants