Open ig-garcia opened 3 weeks ago
The target (and minimum version) is specified in cflags (i.e. --target=aarch64-linux-android21). If you look at the aarch64-linux-android21-clang
file it's just a wrapper that adds the --target
argument.
Also the linker error looks like you need to link with libc++, so a missing linker flag, but Rust doesn't use libc++ so I'd assume that whichever crate is compiling and linking c++ code should take care of that.
Also the linker error looks like you need to link with libc++, so a missing linker flag, but Rust doesn't use libc++ so I'd assume that whichever crate is compiling and linking c++ code should take care of that.
The C library I am compiling is not compiling inside Rust itself, it is compiled in the build.rs file of my Rust crate but I am using the Rust std::process::Command
crate to actually call the make
and make install
commands of the C library, passing to it the parameters needed for each Android arch.
I think on Android you can either manually link with libc++_static.a
, or have to include libc++_shared.so
in your APK.
https://developer.android.com/ndk/guides/cpp-support#selecting_a_c_runtime
The target (and minimum version) is specified in cflags (i.e. --target=aarch64-linux-android21). If you look at the
aarch64-linux-android21-clang
file it's just a wrapper that adds the--target
argument.
Finally I verified our C library does not like the format of the compiler + flags from Cargokit, so I will set them manually from paths.
I see there is a env var called CARGO_TARGET_AARCH64_LINUX_ANDROID_LINKER
, is it supposed to be used as the LD
(linker) in the environment or similar?
I think on Android you can either manually link with
libc++_static.a
, or have to includelibc++_shared.so
in your APK.https://developer.android.com/ndk/guides/cpp-support#selecting_a_c_runtime
I actually included the libc++_shared.so
in the APK, in the arm64-v8a folder, but somehow when is packaged into the APK the library loses all its symbols. On the other hand, if I copy same library to an aarch64 folder the symbols are kept, but of course Android does not use it.
Finally I verified our C library does not like the format of the compiler + flags from Cargokit, so I will set them manually from paths.
I have no idea what that means. The --target
argument is a clang argument, nothing to do with your library, unless there is no way to pass custom compile flags, which woould be very weird.
I actually included the libc++_shared.so in the APK, in the arm64-v8a folder, but somehow when is packaged into the APK the library loses all its symbols.
gradle strips libraries (there is a way to configure it not to at project level), but public symbols should not get stripped.
Hello, I am trying to compile for Android a C library that needs to be compiled separately for every Android architecture. This C library is a dependency of a rust library which in turn is also dependency of another rust library which is dependency of the hub crate of rinf. rinf uses Cargokit under the hood. The rust library hub is depending on has a build.rs file where I build the C library.
The C library is building fine, and I can even use it in my crate Rust tests . But when running the Android app, on startup I get this error:
The problem seems to be that the build is not linking with the standard ndk C++ library (like libc++_shared.so).
Also in my Rust crate's build.rs I printed the env variables, and some are set by Cargokit. I get some env vars that look a bit strange, like for example:
Somehow the target arch is not included in these vars... like I would be expecting something like
Please see the difference: the second path has included aarch64-linux-android21- which are the target triplet + the min android version.
When I tried to use these env vars for my compilation it did not work, so I used the ones that seemed to work, as I provided above, some of them include target arch, etc.
So I have a few questions:
Thanks in advance, regards.