Android NDK: rebuild with c++_shared to avoid double libc++ when mixing prebuilts

Aperta
#1,496 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

@fanxiaoyi520 ci sta già lavorando.

Dal 11/9/2026.

  • #1497 di @fanxiaoyi520 — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
50/100
Tipo di issue
Documentazione
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
android, cmake, cpp
Ambito
documentation

Direzione di ricerca

The proposed change is a new docs/android-ndk.md covering the ANDROID_STL=c++_shared rebuild recipe in the issue body. Check include/yaml-cpp/dll.h to confirm the YAML_CPP_API visibility mapping the notes cite, and look at the existing docs layout before adding the file. Done means a maintainer has agreed to the doc PR and the recipe is written up accurately, with no proprietary binaries.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Problem

When integrating a prebuilt libyaml-cpp.so into an Android app/native module that already uses the NDK shared C++ runtime (libc++_shared.so / ANDROID_STL=c++_shared), it is easy to end up with two C++ runtimes in one process ("double libc++").

Symptoms are typically load/link failures or hard-to-debug crashes around STL types crossing .so boundaries—not YAML parsing logic itself.

Cause

STL linkage mismatch between:

  • the prebuilt yaml-cpp (often built with a different STL / static vs shared), and
  • the app / other native libs that expect a single shared libc++_shared.
Workaround that worked for us

Rebuild yaml-cpp from source with the same shared STL as the host app, then replace the mismatched prebuilt.

Verified with tag yaml-cpp-0.6.3 (also tried newer trees; 0.6.3 matched our ABI needs):

cmake -S . -B build-android \
  -DCMAKE_TOOLCHAIN_FILE=$NDK/build/cmake/android.toolchain.cmake \
  -DANDROID_ABI=arm64-v8a \
  -DANDROID_PLATFORM=android-30 \
  -DANDROID_STL=c++_shared \
  -DYAML_BUILD_SHARED_LIBS=ON \
  -DCMAKE_BUILD_TYPE=Release \
  -DCMAKE_CXX_FLAGS="-fvisibility=hidden -fvisibility-inlines-hidden"

cmake --build build-android --config Release

Notes:

  1. Keep one libc++_shared.so in the final APK (prefer the NDK/app copy; do not ship a second conflicting copy).
  2. include/yaml-cpp/dll.h already maps YAML_CPP_API to __attribute__((visibility("default"))) on non-MSVC when building the shared library. That matters if you compile with -fvisibility=hidden so exported symbols stay visible across .so boundaries.
  3. This report is a generic rebuild recipe only—no proprietary binaries attached.
Question for maintainers

Would you accept a short doc PR (e.g. docs/android-ndk.md) capturing the ANDROID_STL=c++_shared shared-library rebuild notes above? Happy to open one if useful.

Lingua principale
C++
Stelle
6.1k
Fork
2.2k
Merge medio
22h 2m
PR unite (30g)
1

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jbeder/yaml-cpp

Tutte le issue di jbeder/yaml-cpp

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.