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).
Related
Current libgit2 instructions for Android state the following:
Extract toolchain from NDK using, make-standalone-toolchain.sh script. Optionally, crosscompile and install OpenSSL inside of it. Then create CMake toolchain file that configures paths to your crosscompiler (substitute {PATH} with full path to the toolchain)- https://github.com/libgit2/libgit2
However, it appears that make-standalone-toolchain.sh is now obsolete:
Warning: If using r19 or newer, follow the Use the NDK with 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. - https://developer.android.com/ndk/guides/standalone_toolchain
Is there a place with updated libgit2 instructions for building it for 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.
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.
What is the path to the ARM cross-compiler in the present distribution of the Android SDK? I am on Mac El Capitan. (I have read many different things all around and I'm a bit confused on how to declare the CROSS_COMPILE variable for compiling the kernel.)
After some investigation, I am now able to answer my own question.
First, the cross-compiler is not part of the SDK, but of the NDK (Native Development Kit). So the first thing to do is fetching (installing) the NDK. I did this easily from Android Studio (which I use just to manage packages).
Second, the toolchain (the stack of tools used to build up a binary) is not there in the NDK directory tree: it has to be extracted. (It is not clear to me yet what this technically means - comments are welcome - what I understand is that the toolchain has to be "created".) To this aim, there is a Python script in the NDK directory tree, namely:
ndk-bundle/build/tools/make_standalone_toolchain.py
Since I am interested in compiling for an ARM architecture, I invoked this by:
./make_standalone_toolchain.py --arch arm --install-dir <desired toolchain location>
At this point, a toolchain is extracted to the <desired toolchain location>, and inside there a cross-compiler may be found.
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