fix: link libc++ statically — crash on launch due to missing libc++_shared.so

- Set cpp_link_stdlib(None) to suppress cc crate's automatic linking
- Explicitly link both c++_static and c++abi with NDK sysroot search path
- Fixes RTTI vtable symbol (_ZTVN10__cxxabiv117__class_type_infoE) error
- Verified: only liblog.so remains as dynamic dependency

Closes #001

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Claude
2026-04-05 05:07:25 +00:00
parent 622fdee51f
commit 778f4dd428
2 changed files with 15 additions and 0 deletions

View File

@@ -36,6 +36,21 @@ fn main() {
// libc++_static.a — STL (containers, strings, algorithms) // libc++_static.a — STL (containers, strings, algorithms)
// libc++abi.a — ABI (RTTI, exceptions, typeinfo vtables) // libc++abi.a — ABI (RTTI, exceptions, typeinfo vtables)
// Both are required; cc crate's cpp_link_stdlib only handles the first. // Both are required; cc crate's cpp_link_stdlib only handles the first.
//
// We also need to tell the linker where to find them in the NDK sysroot.
if let Ok(ndk) = std::env::var("ANDROID_NDK_HOME") {
let arch = if target.contains("aarch64") {
"aarch64-linux-android"
} else if target.contains("armv7") {
"arm-linux-androideabi"
} else if target.contains("x86_64") {
"x86_64-linux-android"
} else {
"aarch64-linux-android"
};
let lib_dir = format!("{ndk}/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/{arch}");
println!("cargo:rustc-link-search=native={lib_dir}");
}
println!("cargo:rustc-link-lib=static=c++_static"); println!("cargo:rustc-link-lib=static=c++_static");
println!("cargo:rustc-link-lib=static=c++abi"); println!("cargo:rustc-link-lib=static=c++abi");
} else { } else {

Binary file not shown.