Using a new method in latest Android NDK libc - android

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

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

Clang/LLVM enabling OpenMP-Support

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.

Is Android SDK version relevant when compiling libraries using NDK?

First step: I use QtCreator to compile a bunch of libraries (.so files) + a GUI test program to test those libraries on an Android device.
Second step: After I tested them, I re-compile the libraries without the GUI test program and send them to a client who's going to integrate those .so file in its own Andoid application (generating and apk), not using QtCreator anymore. I do this step using QtCreator (because it's setup, very easy for me to just remove the GUI test program and hit compile), but I'm pretty sure they could also be compiled directly using ndk-build if I work on writting the correct make files for that.
When I re-compile the libraries, there's still a "Android build SDK" option under "Build Android APK" set to "android-22" in QtCreator. However, my client generates its final app for "android-19". And we are wondering if this could be a problem.
My understanding is that my .so files generated in "second step" are built using the NDK only (SDK is not used, so android API version "android-22" is irrelevant as I do not generate any APK...). So there should be no compatibility issue when those .so files are integrated in an application, as far as the same NDK version is used.
Am I right?

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.

Android and cross-compiling

I have a Linux library that needs to be compiled under Android. I understand that should be used to build this program: / home/user/android-ndk/build/prebuilt/linux-x86/arm-eabi-4.4.0/bin/arm-eabi-gcc and then compile a ndk-build . I think right? Assembly via the utility should work correctly?
You need to install the Native Development Kit (NDK) and read through the documentation in the NDK about the build process. The NDK basic info is at http://developer.android.com/sdk/ndk/index.html, and you'll need to install an appropriate version of Cygwin (if you're using Windows).
It comes with a prebuilt compiler, so you shouldn't have to rebuild that.

Categories

Resources