fix: also link libc++abi for RTTI — resolve missing __class_type_info vtable

Previous fix linked c++_static but not c++abi. Android NDK splits the
static C++ runtime into two archives: libc++_static.a (STL) and
libc++abi.a (RTTI/exceptions). Without c++abi, dlopen fails on
_ZTVN10__cxxabiv117__class_type_infoE.

Now using cpp_link_stdlib(None) to suppress cc crate auto-linking, then
explicitly linking both c++_static and c++abi via cargo:rustc-link-lib.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Siavash Sameni
2026-04-05 09:00:14 +04:00
parent b204213a01
commit 622fdee51f
2 changed files with 59 additions and 44 deletions

View File

@@ -13,7 +13,7 @@ fn main() {
cc::Build::new()
.cpp(true)
.std("c++17")
.cpp_link_stdlib(Some("c++_static"))
.cpp_link_stdlib(None)
.file("cpp/oboe_bridge.cpp")
.include("cpp")
.include(oboe_path.join("include"))
@@ -25,12 +25,19 @@ fn main() {
cc::Build::new()
.cpp(true)
.std("c++17")
.cpp_link_stdlib(Some("c++_static"))
.cpp_link_stdlib(None)
.file("cpp/oboe_stub.cpp")
.include("cpp")
.compile("oboe_bridge");
}
}
// Android NDK splits the static C++ runtime into two archives:
// libc++_static.a — STL (containers, strings, algorithms)
// libc++abi.a — ABI (RTTI, exceptions, typeinfo vtables)
// Both are required; cc crate's cpp_link_stdlib only handles the first.
println!("cargo:rustc-link-lib=static=c++_static");
println!("cargo:rustc-link-lib=static=c++abi");
} else {
// Non-Android: always use stub
cc::Build::new()