Clang/LLVM enabling OpenMP-Support - android

I am using Visual Studio 2017 Community Edition on Windows. My goal is to build a cross-plattform shared c++ library for mobile devices. So far i used the corresponding c++ development template.
After setting everything up i can't see how to enable openmp in the compiler. Coming from Android Studio it was sufficient to add "-fopenmp" to the compiler flags. VS seems to support equal compilers in this template gcc 4.9 and clang 3.8. I read that under "Configuration Properties -> C/C++ -> Language" there should be an option to enable OpenMP support, but in case of this template the option is not there. (I tested other c++ template which offers this possibility)
Even the compiler flag "-fopenmp", results in an "undefined reference error" of openmp. As i researched more i looked up the different toolchains which are delivered by VS, the LLVM toolchain seems not including omp header oder prebuilts.
Maybe some one can help, the code was working in android studio via cmake. I added all necessary dependencies through visual studio and installed the necessary vs packages.
Edit:
Maybe i should add that the platforms i want to build for are ARM and ARM64.

I solved this issues and maybe it helps someone. I switched the compiler to gcc in the already installed version. The issues was that i didn't set the compiler flag -fopenmp at the linker.
Now it is building, but i still don't know why clang/llvm is not working.

Related

In androidstudio default toolchain `aarch64-linux-android-gcc` does not exist

According to this page I don't need to be using the standalone toolchain anymore. I updated to NDK 20 so this should work for me I thought.
However, as soon as I started to try and recompile my C++ dependencies (ffmpeg at first), I found out aarch64-linux-android-gcc is needed. But this file does not exist anywhere under the $NDK dir (it does exist in the standalone toolchain directory).
So I'm confused, because the impression I got from this
Warning: If using r19 or newer, follow the Other Build Systems document for instructions on using the NDK toolchains with arbitrary build systems. As of r19, the NDK's default toolchains are standalone toolchains, which renders this process unnecessary.
was that I could use the existing toolchain. And my question is: Is that information wrong, should I continue using the standalone toolchain, or am I doing something else wrong?
Standalone toolchains won't help you if your build is using GCC. GCC is no longer supported by the NDK. You need to either (preferably) convert the build to use Clang or (understanding that this means you're going to be struggling with bugs that have since been fixed) downgrade your NDK to a version that supported GCC (r17).

Unable to select JNI build variant after upgrading Android Studio to version 3.3

I have a Java Android project that includes JNI code written in C.
I often need to debug into the native code and before upgrading Android Studio to version 3.3 it was working.
Now in my project view I don't have any code in my cpp folder. I have confirmed that all of the C libraries are in the folder on my HDD. The CMAKE file is also missing from the project view but is also in the correct place on my HDD.
I have not changed any code from my source control since upgrading.
I am using
'com.android.tools.build:gradle:3.3.0'.
In the Build Variants section next to my JNI module I just have five dashes instead of the debug/production options.
I have uninstalled and reinstalled android studio too.
Is it possible after upgrading I need to add something to my configuration to correct including CMAKE?
I had the same issue, just figured it out. In AndroidStudio 3.3.1, they changed things around a bit I guess. Now you have to link your NDK build to the app you are building it as part of.
This is documented at: https://developer.android.com/studio/projects/gradle-external-native-builds
The section, "Use the Android Studio UI" is what you want.

Building with Address Sanitizer on Android but with CMake

I am trying to build a .so for android and I want to build with address sanitizer but the only instructions I see are for Android NDK based Makefiles, but I am using the newer endorsed CMake setup. Just adding the flag -fsanitize=address wasn't enough as the clang runtime library was missing.
what is the correct thing to add in my CMakeLists for Android built libraries?
You also need to prepare your device as described in documentation. You have to run asan_device_setup script from NDK. It will put asan .so on the device.

Visual Studio 2015: Build C++ 11 library for Android

I'm working on porting this digital logic library to Android. However, I keep getting build errors involving missing functions from standard libraries like CMath, or missing C++11 libraries when trying to compile the Android project. Searching has revealed that issues with building C++ for Android in Visual Studio are rather common, but none of the suggestions I have found so far have helped. Here is the project with the build errors.
I have tried changing the target platform, changing the platform toolset, and changing the use of STL. Various combinations of the settings. I can't seem to get anything building.
Should I just give up on Visual Studio for my mobile C++ code and build those libraries elsewhere?
After creating a new branch with only Android code (as opposed to the previous cross platform mobile branch) and further playing with settings and searching, I arrived at the solution. These settings will allow the code to compile:
Compiler: Clang 3.8
Use of STL: GNU STL Static library
C++ Language Standard: C++11
Linker Command Line Additional Options: -lm
The designation that made it work was the -lm linker option to ensure it was properly linking the math library.

Using a new method in latest Android NDK libc

I'm using the latest version of the NDK (as of a few weeks ago), r10d, and using the build tools to build python and some extensions in python. Using the build tools, I create a shared object that then gets linked into my project in Android Studio. In my build environment outside of Android studio, where I build the embedded Python library, I use the latest platform automatically, so in this case it is using NDK_ROOT/platforms/android-21.
All built fine, but then it crashed on a device running 4.4.4 with the error: java.lang.UnsatisfiedLinkError: dlopen failed: cannot locate symbol "epoll_create1" referenced by "libMyNativeIntfc.so"...
So, doing some research, I see that one of my python extensions uses this method, and it is defined in the NDK's sys/epoll.h. However, it was added to bionic in platform android-21 (I'm surprised I haven't encountered this already as I've been building since API 16). In previous platform libraries, the method is not exported. So I believe this method was just added to the latest android-21 libc (I verified it exists in the android-21 libc.a library and headers but not android-19 and below.
I'm looking for a bit of advice for the best way forward. As it stands, I think there are a couple of options.
1) Build against android-20 NDK platform instead, in which case my configure scripts will cull out the use of the method in my extension, and all will be happy.
2) Change the extension code to call epoll_create() instead, but I really would like to keep it the same as the upstream repo.
3) Link against the static libc.a in the android-21 usr/lib directory...now this one I'm a bit wary of. Would this be okay?
Thanks,
Chris

Categories

Resources