FindOpenMP.cmake error on Android NDK wrt clang.

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

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/Tencent/ncnn/issues/1771

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 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

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.

Thanks for tracking that down. Please open an issue tracker entry to track this problem.

Okay did. https://gitlab.kitware.com/cmake/cmake/-/issues/21725

1 Like