IT++ and FFTW libraries need to be compiled specific to Application Binary Interface (ABI) for Android NDK.
These are the following ABIs:
Further details can be found over here-> https://developer.android.com/ndk/guides/abis.html
IMPORTANT: Compile FFTW before IT++ as IT++ incorporates FFTW's archived library inside its own shared library.
FFTW compilation for NDK:
IT++ compilation with FFTW for NDK:
How to make IT++ functions available to the C++ code in Android?
These are the following ABIs:
- X86
- X86_64
- armeabi
- mips
- mips64
Further details can be found over here-> https://developer.android.com/ndk/guides/abis.html
IMPORTANT: Compile FFTW before IT++ as IT++ incorporates FFTW's archived library inside its own shared library.
FFTW compilation for NDK:
- Download the latest package from http://www.fftw.org/
- Unzip and go inside the folder:
cd ~/Downloads/fftw-3.3.5 - Set the compilation parameters specific to an ABI. The example is for 'armeabi'.
export NDK_ROOT="/Users/rajanya/Library/Android/sdk/ndk-bundle"export PATH="$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/:$PATH"export SYS_ROOT="$NDK_ROOT/platforms/android-21/arch-arm/"export CC="arm-linux-androideabi-gcc --sysroot=$SYS_ROOT"export LD="arm-linux-androideabi-ld"export AR="arm-linux-androideabi-ar"export RANLIB="arm-linux-androideabi-ranlib"export STRIP="arm-linux-androideabi-strip"export DEST_DIR="$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/user"
- Generate Makefile:
./configure --host=arm-eabi --build=i386-apple-darwin10.8.0 --prefix=$DEST_DIR LIBS="-lc -lgcc" --disable-fortran make && make install
IT++ compilation with FFTW for NDK:
- Download the latest package from http://itpp.sourceforge.net/4.3.1/installation.html
- Unzip and go inside the folder:
cd ~/Downloads/itpp-4.3.1 mkdir build && cd build/- Download https://github.com/taka-no-me/android-cmake to obtain cmake toolchain file.
- Open cmake GUI. If cmake not present , visit https://cmake.org/download/
- In cmake, add the following entries:
- Where is the source code:
~/Downloads/itpp-4.3.1 - Where to build the binaries:
~/Downloads/itpp-4.3.1/build
- Where is the source code:
- Then click '+Add Entry' button to add the following key-value pair:
ANDROID_NDK -> PATH -> ~/Library/Android/sdk/ndk-bundleANDROID_NATIVE_API_LEVEL -> STRING -> 17ANDROID_TOOLCHAIN_NAME -> STRING -> arm-linux-androideabi-4.9
- Click
Configure -> Specify toolchain file for cross-compiling -> ~/Downloads/android-cmake-master/android.toolchain.cmake - Click
Generate. - Return back to terminal. Run
make && make installto build & install the shared library at/usr/local/lib/
How to make IT++ functions available to the C++ code in Android?
- Copy /usr/local/lib/libitpp.so to <app_path>/app/libs/
- Enter the following lines in the CMake file:
- set(distribution_DIR ${CMAKE_SOURCE_DIR}/../../../libs)
- add_library(lib_itpp SHARED IMPORTED)
- set_target_properties(lib_itpp PROPERTIES IMPORTED_LOCATION
${distribution_DIR}/lib/${ANDROID_ABI}/libitpp.so) - target_link_libraries(native-libandroidlib_itpp)
- #include<itpp/itbase.h> in your native-lib.cpp file.
Hello,
ReplyDeleteI followed the instruction for ITPP and make && make install were successful. I now struggle with having itpp header files available in my android NDK project in which I use CMake.
My CMake entry for itpp is:
set(itpp_DIR /usr/local/lib)
find_library(itpp REQUIRED)
include_directories(${itpp_INCLUDE_DIR})
I still have e.g.
#include
not available.
Can anyone give me a hint what I am doing wrong? Than you.
This comment has been removed by the author.
DeleteSorry there is a mistake. I wanted to say that after all I still have e.g.
Delete# include < itpp / itbase . h >
not available for my cpp files
Hi Michal,
DeleteI am happy to know that you referred to my blog :) I have appended a new section. Please refer to it and let me know if that solves your problem.
Hello,
ReplyDeleteThank you for adding some more insights about Android Studio and CMake.
Unfortunately I still have issues with making it work.
1) What do you mean exactly by:
"NOTE: Repeat the above steps for each and every ABI" ?
Do you mean repeating the steps only for "IT++ compilation with FFTW for NDK:" or also for FFTW? I have errors when I run `make && make install` for abis other than `arm-linux-androideabi-4.9`.
2) Also after I successfuly complete all steps for `arm-linux-androideabi-4.9` I cannot find libittp.so at usr/local/lib but I find it at `~/Downloads/itpp-4.3.1/build/itpp/` instead. When I grab the .so file and link it in Android Studio project CMake i can successfuly sync gradle but when I try to build project I get:
Error:error: linker command failed with exit code 1 (use -v to see invocation)
Error:error: ../../../../libs/libitpp.so: incompatible target
Can you give any hints? Thanks a lot.
Ok, I do not have errors when building for other ABIs, I have not been cleaning cmake cash before compiling for other ABI. Now it works.
DeleteI organise the output libittp.so files in separate folders and then will try to plug one of them into Android Studio project CMakeLists.txt . So far I tried 3 of them and result is always :
"Error:error: linker command failed with exit code 1 (use -v to see invocation)
Error:error: ../../../../libs/libitpp.so: incompatible target"
Ok I have repeated steps for ITPP for all ABIs and my android studio project compiles well when I use the following CMakeLists entries:
Deleteset(distribution_DIR ${CMAKE_SOURCE_DIR}/libs)
add_library(lib_itpp SHARED IMPORTED)
set_target_properties(lib_itpp PROPERTIES IMPORTED_LOCATION ${distribution_DIR}/${ANDROID_ABI}/libitpp.so)
I also added `lib_itpp` to my `target_link_libraries` cmake command at the end of the CMakeLists.txt file.
I feel like I am close. The last remaining issue is that besides everything should be compiled Android Studio does not recognize:
#include
throwing: Error:fatal error: 'itpp/base.h' file not found
Any hints what may be wrong? I suspect i have a bug in the CMakeLists.txt
You need to put the headers in the 'include' folder.
DeleteEverything works now :) Thank you a lot for this blog article and for your support.
Delete