terdev
terdev

Reputation: 87

can not link to FFTW library for Android NDK

I want to use FFTW3 for my Android NDK project. Therefore I build the library on MacOs for Android as follows:

./configure --host=aarch64-none-linux-android33 --enable-threads --enable-float
sudo make 
sudo make install

Then I linked it in build.gradle:

externalNativeBuild {
        cmake {
           cppFlags "-L/path/to/fftwf/.libs/ -lfftw3f_threads -lfftw3f -lm",
                    "-L/path/to/fftwf/threads/.libs/ ",
                    "-O3 -g --std=c++17 -fopenmp"
        }
}

Then I included FFTW into the CMake process of CMakeLists.txt:

add_library( demo SHARED native-lib.cpp )
# ....
add_subdirectory(fftwf)
include_directories(fftwf/api)

target_include_directories( fbi PRIVATE ${CMAKE_SOURCE_DIR}/fftwf/api )
target_include_directories( fbi PRIVATE ${CMAKE_SOURCE_DIR}/fftwf/threads/.libs )
target_link_libraries( demo fftw3 )   

After including FFTW with #include "fftwf/api/fftw3.h" I get the following linking error:

ld: error: undefined symbol: fftwf_threads_set_callback
>>> referenced by fftw-bench.c:101   (/path/to/fftwf_3.3.10/tests/fftw-bench.c:101)
>>>               fftwf_3.3.10/CMakeFiles/bench.dir/tests/fftw-bench.c.o:(useropt)

I could not find anything in the FFTW3.3.10 docs that specify how to correctly link the library when using threads. Since fftwf_threads_set_callback is the first occurrence of a call to the FFTW thread library, I assume that something went wrong in the build process, but I could not find any flaws when comparing to the documentation.

Upvotes: 0

Views: 92

Answers (1)

terdev
terdev

Reputation: 87

I could solve it by building FFTW with CMake:

add_subdirectory(fftw)

add_library( demo SHARED native-lib.cpp )

target_include_directories( demo PRIVATE ${CMAKE_SOURCE_DIR}/fftwf/api )
target_include_directories( demo PRIVATE ${CMAKE_SOURCE_DIR}/fftwf/threads )

target_link_libraries( demo fftw3f fftw3f_threads )

Somehow the fftw/CMakeLists.txt did not enable single precision and threads, like I specified in the ./configure flags, so I manually enabled it:

option (ENABLE_THREADS "Use pthread for multithreading" ON)
option (ENABLE_FLOAT "single-precision" ON)

I initially also used the --enable-neon flag, but that also yield a ld error and I could not find a way to manually adjust the CMakeLists, so I had to set #define HAVE_NEON 0.

Upvotes: 0

Related Questions