0

我正在尝试在我的 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"
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

这会正确生成 fftw3/lib 和 fftw3/include 目录,一切看起来都很好。然后我想编译这个 .cpp 文件:

#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;
  }
} 

要生成共享库,请使用以下 Android.mk 生成文件:

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)

当我运行 Android.mk 时,我收到一些未定义的引用错误,例如:

/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?

4

1 回答 1

1

我刚刚删除了 --build 参数并且错误消失了

于 2013-10-09T20:56:23.803 回答