Android NDK Crash in libomp.so at __kmpc_barrier with FluidSynth and OpenMP
12:52 27 Aug 2025

I'm developing an Android app using the NDK that plays MIDI files with FluidSynth, integrated with a Java frontend. The app crashes with a native crash in libomp.so at __kmpc_barrier, and I suspect it's related to OpenMP usage in FluidSynth or my native code.

Crash Log

The crash occurs in a non-main thread (Thread-63):

22:08:59.062  A  Cmdline: com.example.testbpm
22:08:59.062  A  pid: 29282, tid: 30077, name: Thread-63  >>> com.example.testbpm <<<
22:08:59.062  A        #00 pc 000000000004c2fc  /data/app/~~-WRpGwDXkyQ8QTPeYwjCZQ==/com.example.testbpm-9jz8ic94WHX2gMcs0WYMmA==/base.apk!libomp.so (offset 0x1440000)
22:08:59.062  A        #08 pc 000000000005e188  /data/app/.../base.apk!libomp.so (__kmpc_barrier+320)
22:08:59.062  A        #09 pc 00000000000e644c  /data/app/.../base.apk!libomp.so (__kmp_invoke_microtask+156)

Project Setup

  • Language: C++ (NDK) for native code, Java for UI

  • Libraries: FluidSynth for MIDI playback, libomp.so for OpenMP

  • NDK: r23 or later

  • Functionality: Loads MIDI + SoundFont, parses sections (Intro, Main, Fill, Ending), supports transitions and tempo control

Suspected Cause

The crash at __kmpc_barrier suggests an issue with OpenMP thread synchronization. Possible reasons:

  • Dynamic linking issue: libomp.so not properly bundled in APK
  • TLS issues on Android (non-main threads)
  • FluidSynth internal OpenMP usage conflicting with std::thread / std::mutex
  • NDK compatibility / missing static linking

What I’ve Tried

  • Ensured libomp.so is loaded in MainActivity.java.
  • Used std::mutex for thread safety.
  • Verified lib/arm64-v8a/libomp.so is inside APK (via APK Analyzer).
  • Tested on multiple Android 12+ devices → crash persists.
  • Added Logcat debugging (no extra errors before crash).

Questions

  • How can I confirm if libomp.so is properly included in the APK?
  • Should I link OpenMP statically (-fopenmp -static-openmp) to avoid dynamic issues?
  • Is there a way to disable OpenMP in FluidSynth or replace it with std::thread?
  • Could this be NDK compatibility / TLS-related?

Any suggestions to resolve this crash or debug further? Should I share my CMakeLists.txt as well?

android c++ android-ndk openmp fluidsynth