# FindOpenMP.cmake error on Android NDK wrt clang.

**URL:** https://discourse.cmake.org/t/findopenmp-cmake-error-on-android-ndk-wrt-clang/2579
**Category:** Development
**Created:** [January 20, 2021, 12:12am UTC](https://discourse.cmake.org/t/findopenmp-cmake-error-on-android-ndk-wrt-clang/2579 "2021-01-20T00:12:18Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Steven\_Braeger](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@Steven\_Braeger](https://discourse.cmake.org/u/Steven_Braeger)
#### Post date: [January 20, 2021, 12:12am UTC](https://discourse.cmake.org/t/findopenmp-cmake-error-on-android-ndk-wrt-clang/2579/1 "2021-01-20T00:12:18Z")

</div>

Android as of NDK r20 does not have support for gcc except through Clang.

[https://android.googlesource.com/platform/ndk/+/master/docs/ClangMigration.md](https://android.googlesource.com/platform/ndk/+/master/docs/ClangMigration.md)

However, modern versions of Clang on android inside the NDK no longer provide dynamic linking capability for openmp.

[https://github.com/android/ndk/issues/1028](https://github.com/android/ndk/issues/1028)

[https://github.com/Tencent/ncnn/issues/1771](https://github.com/Tencent/ncnn/issues/1771)

[https://github.com/llvm-project/llvm-project-submodule/commit/67728311735cf648591938e8e2ac2f864b8ed140](https://github.com/llvm-project/llvm-project-submodule/commit/67728311735cf648591938e8e2ac2f864b8ed140)

When a project is build on android with -fopenmp, it builds, but it fails at runtime with “dlopen cannot open libomp.so” [https://github.com/Tencent/ncnn/issues/1771](https://github.com/Tencent/ncnn/issues/1771) because dynamic libomp is no longer supported.

The required fix for this on android is to add -static-omp on Android versions of clang that support that flag, or to add "`-Wl,-Bstatic -lomp -Wl,-Bdynamic" on versions of clang that do not.`

[https://github.com/android/ndk/issues/1028#issuecomment-524481843](https://github.com/android/ndk/issues/1028#issuecomment-524481843)

This should be handled internally by FindOpenMP.cmake on platforms where it is relevant: e.g., if -static-omp is required by the local clang platform (initially, Android) and libomp.so is not enabled on the target platform, then OpenMP::OpenMP public link settings should include the correct flag to enable static linking without further intervention by the user.

This issue recently cost me about 8 hours to resolve and debug.

I will write a patch to do this but I wanted to get commentary on it before I took the time.

---

<div class="post-metadata">

### Author: ![brad.king](https://discourse.cmake.org/user_avatar/discourse.cmake.org/brad.king/32/11_2.png) [@brad.king](https://discourse.cmake.org/u/brad.king)
#### Post date: [January 20, 2021, 2:18pm UTC](https://discourse.cmake.org/t/findopenmp-cmake-error-on-android-ndk-wrt-clang/2579/2 "2021-01-20T14:18:41Z")

</div>

Thanks for tracking that down. Please open an [issue tracker entry](https://gitlab.kitware.com/cmake/cmake/-/issues) to track this problem.

---

<div class="post-metadata">

### Author: ![Steven\_Braeger](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/s/b487fb/32.png) [@Steven\_Braeger](https://discourse.cmake.org/u/Steven_Braeger)
#### Post date: [January 20, 2021, 8:40pm UTC](https://discourse.cmake.org/t/findopenmp-cmake-error-on-android-ndk-wrt-clang/2579/3 "2021-01-20T20:40:05Z")

</div>

Okay did. [https://gitlab.kitware.com/cmake/cmake/-/issues/21725](https://gitlab.kitware.com/cmake/cmake/-/issues/21725)
