-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Cross-compile for Android meets linker error #138488
Comments
Did you tell rustc to use the linker from the NDK? What cargo command did you use build? |
@bjorn3 export PATH=${PATH}:${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/
export CC_aarch64_linux_android=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang
export CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER=${ANDROID_NDK}/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android24-clang |
The linker is found correct. However, ndk doesn't contain pthread and libc by default unfortunately, and this leads to the problem. |
My ndk is the official ndk. |
What
The ndk has to contain libc at the very least. Without it, it would be impossible to link any executable, which is kind of the whole point of the ndk. |
--target aarch64-linux-android |
I think you need to set the linker using |
I tried this line, and it does not help.
|
The following error is still there.
For |
The complete error message is below:
|
Wait, the crate that failed to build is getting compiled for the host as it is a build script. Are you able to compile any executable for your host at all? Do you have the build-essentials package installed? |
Do you mean that my error comes from building process for the host? |
Yes
It looks like it found the right linker. I think you are missing the libc6-dev package (and maybe one of the |
I understood! It's my fault, I've manually set my system linker to the ndk linker. |
Thank you very much! Wish you a good day! |
When I tried to cross-compile a rust project for android, I met the following linker problem.
cargo automatically add lots of linker flags when cross compiling the dependencies: "-lgcc_s" "-lutil" "-lrt" "-lpthread" "-lm" "-ldl" "-lc".
These linker flags are not available for ndk clang compiler I suppose, leading to linker error. Actually these automatically added linker flags are not even required by the dependencies.
How to fix it? Is it a rust issue for android cross-compilation? Is it possible to disable such default linker flags?
To replicate such error, just cross compile any rust project which has a dependency library, and it may show up.
Meta
I've tested all possible version for aarch64-linux-android, including
rustc --version --verbose
:They all present the same linker error above.
Backtrace
The text was updated successfully, but these errors were encountered: