budderick
budderick

Reputation: 304

Building shared FFTW library for Android

I am trying to build a shared library of FFTW by means of the following script:

INSTALL_DIR="`pwd`/jni/fftw3"
SRC_DIR="`pwd`/../fftw-3.3.4"

cd $SRC_DIR

NDK_ROOT=/path_to_android/Sdk/ndk-bundle

export PATH="$NDK_ROOT/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-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"

mkdir -p $INSTALL_DIR
./configure --enable-shared --host=arm-eabi --build=i386-linux --prefix=$INSTALL_DIR LIBS="-lc -lgcc" --enable-float

make
make install

exit 0

However, after executing the script I always only receive a static FFTW library even though I am using the enable-shared parameter. Is there any other way to generate the shared library file?
I really need a shared library since Android Studio demands a shared library to compile additional JNI sources.

Update:
Based on @bullsy's answer, I could build the shared library by chaning the host parameter to --host=arm-linux-androideabi. The resulting problem is that FFTW generates a versioned shared library with library files libfftw.so.3 and libfftw.so.3.4.4. I found a tutorial that shows how to convert these files into .so files. While working on libfftw3.so or libfftw3.so.3, I always received the error that file is not a (regular) file so I tried everything on libfftw3.so.3.4.4:

rpl -R -e libfftw3.so.3 libfftw3_3.so libfftw3.so.3.4.4 
mv libfftw3.so.3.4.4 libfftw3_344.so
ln -sfn libfftw3_344.so libfftw3.so.3
mv libfftw3.so.3 libfftw3_3.so

I had to add the ln command manually. Without changing the symlink, Gradle could not find libfftw3_3.so during the building process of the apk.
So my application is running now with the shared libs but it is also possible to generate shared FFTW libs with single precision (-enable-float)?


Another approach was to take the static library file and to build a shared library file by means of an Android.mk and ndk-build:

LOCAL_PATH := $(call my-dir)

include $(CLEAR_VARS)

LOCAL_MODULE := fftw3
LOCAL_SRC_FILES := fftw3/lib/libfftw3.a
include $(PREBUILT_STATIC_LIBRARY)

LOCAL_MODULE    := fftw_wrapper
LOCAL_C_INCLUDES := /path_to_fftw_headers/include
LOCAL_C_INCLUDES += /pat_to_wrapper/fftw_wrapper.h
LOCAL_SRC_FILES := fftw_wrapper.cpp
LOCAL_SHARED_LIBRARIES := fftw3f
include $(BUILD_SHARED_LIBRARY)

But this approach always returns undefined reference errors, e.g. undefined reference to 'fftw_malloc'. I have also tried it without the --build parameter as it is explained in this question: Using FFTW on Android undefined references

Whenever I use the static library, my application runs fine, even when I statically link the fftw_wrapper in the Android.mk. However, since my C/C++ imports are all defined in the app Gradle file of Android Studio, I do not want to change back to Android.mk files. Is there any other solution?

Upvotes: 0

Views: 1797

Answers (1)

Francesca Nannizzi
Francesca Nannizzi

Reputation: 1705

Try using

--host=arm-linux-androideabi

instead. This tells configure 'Hey, I'm building for a linux variant', which makes shared libraries the default choice.

Upvotes: 1

Related Questions