问题描述
我想在我的Android应用程序中使用FFTW。我已遵循教程并且能够在OSX上使用这个build.sh以浮点精度建立fftw:
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
导出SYS_ROOT =$ NDK_ROOT / platforms / android-14 / arch-arm /
export CC =arm-linux-androideabi-gcc --sysroot = $ SYS_ROOT
export LD = 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
这将正确生成fftw3 / lib和fftw3 / include目录,一切似乎都很好。
然后我要编译这个.cpp文件:
#include./fftw3/include/fftw3.h
externC{
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); / *根据需要重复* /
fftwf_destroy_plan(p);
fftwf_free(in); fftwf_free(out);
return 42;
}
}
要生成共享库,请使用以下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)
#这里我们给出我们的模块名和源文件
LOCAL_MODULE:= FooPlugin
LOCAL_SRC_FILES:= FooPlugin.cpp
LOCAL_SHARED_LIBRARIES:= fftw3f
include $(BUILD_SHARED_LIBRARY )
当我运行Android.mk时,我得到一些未定义的引用错误, p>
/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'
结构fftwf_complex和fftwf_plan很好,因为这些在fftw.h中定义,但fftwf_malloc,fftwf_free,fftwf_destroy,fftwf_plan_dft_1d等函数在fftw.f03中定义,似乎找不到编译器。
如何修改我的makefile,以便它找到并使用.f03文件,以便我可以在Android上使用fftw?
解决方案我刚刚删除了--build参数和错误的错误
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?
解决方案I just removed the --build parameter and the error disapeared
这篇关于使用FFTW对Android未定义的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!