问题
I'm trying to use FFTW in my Android application. I have followed this tutorial and was able to buid fftw with floating point precision using this build.sh, on OSX:
INSTALL_DIR="`pwd`/jni/fftw3"
SRC_DIR="`pwd`/../fftw-3.3.3"
NDK_ROOT="/Users/awesomeUserName/Desktop/android-ndk-r9"
cd $SRC_DIR
export
PATH="$NDK_ROOT/toolchains/arm-linux-androideabi-4.8/prebuilt/darwin-x86_64/bin/:$PATH"
export SYS_ROOT="$NDK_ROOT/platforms/android-14/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 --host=arm-eabi --build=i386-apple-darwin10.8.0 --prefix=$INSTALL_DIR LIBS="-lc -lgcc" --enable-float
make
make install
exit 0
This generates the fftw3/lib and fftw3/include directories correctly and everything seems fine. I then want to compile this .cpp file:
#include "./fftw3/include/fftw3.h"
extern "C" {
int FooPluginFunction ()
{
fftwf_complex *in, *out;
fftwf_plan p;
in = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * 1024);
out = (fftwf_complex*) fftwf_malloc(sizeof(fftwf_complex) * 1024);
p = fftwf_plan_dft_1d(1024, in, out, FFTW_FORWARD, FFTW_ESTIMATE);
fftwf_execute(p); /* repeat as needed */
fftwf_destroy_plan(p);
fftwf_free(in); fftwf_free(out);
return 42;
}
}
To generate a shared library, using the following Android.mk makefile:
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
LOCAL_MODULE := fftw3
LOCAL_SRC_FILES := fftw3/lib/libfftw3f.a
LOCAL_EXPORT_CPPFLAGS := fftw3/include
include $(PREBUILT_STATIC_LIBRARY)
# Here we give our module name and source file(s)
LOCAL_MODULE := FooPlugin
LOCAL_SRC_FILES := FooPlugin.cpp
LOCAL_SHARED_LIBRARIES := fftw3f
include $(BUILD_SHARED_LIBRARY)
When I run Android.mk, I get a few undefined reference errors like this one:
/Users/awesomeUsername/Desktop/android-ndk-r9/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64/bin/../lib/gcc/arm-linux-androideabi/4.6/../../../../arm-linux-androideabi/bin/ld: ./obj/local/armeabi/objs/FooPlugin/FooPlugin.o: in function FooPluginFunction:jni/FooPlugin.cpp:8: error: undefined reference to 'fftwf_malloc'
The structures fftwf_complex and fftwf_plan are fine because these are defined in fftw.h, but the functions fftwf_malloc, fftwf_free, fftwf_destroy, fftwf_plan_dft_1d, etc. are defined in fftw.f03, which doesn't seem to be found by the compiler.
How can I modify my makefile so that it finds and uses the .f03 files so that I can use fftw on Android?
回答1:
I just removed the --build parameter and the error disapeared
来源:https://stackoverflow.com/questions/18701595/using-fftw-on-android-undefined-references