如何使用CMAKE将FFTW添加到Android项目 [英] How to add FFTW to an Android project using CMAKE

查看:363
本文介绍了如何使用CMAKE将FFTW添加到Android项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用CMAKE将FFTW添加到我的Android项目中,但未能做到这一点.如果有人成功将FFTW添加到了他们的Android项目中,我将不胜感激,尤其是通过cmake而不是ndk-build完成的帮助.

I'm trying to add FFTW to my Android project using CMAKE, but I haven't been able to do so. If anyone has successfully added FFTW to their Android project, I would greatly appreciate any help, especially if it is done through cmake and not ndk-build.

这是我目前在CMakeLists.txt文件中用于将FFTW添加到项目中的代码:

Here is the code that I currently have in my CMakeLists.txt file for adding FFTW to the project:

set(buildDir ${CMAKE_CURRENT_BINARY_DIR}/build)
add_subdirectory(C:/Users/reyna/Documents/HMC/Clinic/Test/fftw-3.3.8 ${buildDir})
set(
        FFTW3_DIR ${buildDir}
        CACHE PATH "Path to internally built FFTW3Config.cmake"
        FORCE
)

find_package(FFTW3 CONFIG REQUIRED)

我收到以下错误消息:

.cxx/cmake/debug/armeabi-v7a/build/FFTW3Config.cmake处的CMake错误:13(包括):
文件 C:/Users/reyna/Documents/HMC/Clinic/AmazonAppTest/Test2/app/.cxx/cmake/debug/armeabi-v7a/build/FFTW3LibraryDepends.cmake 是由export()命令生成的.它不能用作include()命令的参数.而是使用ALIAS目标来通过备用名称引用目标.

CMake Error at .cxx/cmake/debug/armeabi-v7a/build/FFTW3Config.cmake:13 (include):
The file C:/Users/reyna/Documents/HMC/Clinic/AmazonAppTest/Test2/app/.cxx/cmake/debug/armeabi-v7a/build/FFTW3LibraryDepends.cmake was generated by the export() command. It may not be used as the argument to the include() command. Use ALIAS targets instead to refer to targets by alternative names.

>

呼叫堆栈(最近呼叫优先):
CMakeLists.txt:69(find_package)
*尝试:
使用--stacktrace选项运行以获取堆栈跟踪.使用--info或--debug选项运行,以获取更多日志输出.与--scan一起运行以获取完整的见解.
*在 https://help.gradle.org
上获得更多帮助. 1秒钟内无法建立
6个可执行的任务:1个已执行,5个是最新的

Call Stack (most recent call first):
CMakeLists.txt:69 (find_package)
* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 1s
6 actionable tasks: 1 executed, 5 up-to-date

任何人都知道如何解决该错误吗?我不确定该如何处理,因为它似乎来自FFTW Cmake文件.

Anyone have any idea how to fix the error? I am not sure how to approach this, since it seems like it is coming from the FFTW Cmake files.

编辑

因此,我可以在CMAKE中使用以下命令使FFTW以双精度(默认)工作:

So, I was able to get FFTW working with double precision (the default), using the following commands in my CMAKE:

set(CMAKE_INSTALL_PREFIX C:/Users/reyna/Documents/HMC/Clinic/FFTW_Install)
set( FFTW3_DIR C:/Users/reyna/Documents/HMC/Clinic/fftw/fftw-3.3.8)
add_subdirectory(${FFTW3_DIR} ${CMAKE_CURRENT_BINARY_DIR}/fftw_build)
include_directories(C:/Users/reyna/Documents/HMC/Clinic/FFTW_Install/include/)
target_link_libraries (native-lib fftw3 AudioEngine log oboe android)

根据我对CMake的了解,我认为发生的事情如下:

From the little I know about CMake, what I think happens is the following:

  1. 第一个set()命令只是将CMAKE_INSTALL_PREFIX变量设置为我选择的位置.我现在不使用它,但是以后可能会有用.详情请见下文...

  1. The first set() command just sets the CMAKE_INSTALL_PREFIX variable to a place of my choice. I am not using this now, but it could be useful later. More on this below...

第二个set()命令将变量设置为我计算机中FFTW的安装位置.

The second set() command sets a variable to the installation location of FFTW in my computer.

add_subdirectory()命令运行FTTW安装目录中的CMakeList.txt文件,该文件将项目构建到${CMAKE_CURRENT_BINARY_DIR}/fftw_build指定的目录中,该目录位于app/.cxx/cmake/debug/${abi}/fftw_build中.由于CMakeList.txt文件中包含一个add_library()命令,该命令生成一个.so库(对于x86,由于某种原因,它生成一个.a库),因此我可以将我的本机库链接到该目标.我发现这些库已添加到app/build/intermediates/cmake/obj/${abi}文件夹(x86除外,x86由于某种原因将其添加到fftw_build文件夹中).使用上面的target_link_libraries()命令完成链接.

The add_subdirectory() command runs the CMakeList.txt file located in the FTTW install directory, which builds the project into the directory specified by ${CMAKE_CURRENT_BINARY_DIR}/fftw_build, which is located in app/.cxx/cmake/debug/${abi}/fftw_build. Since the CMakeList.txt file has an add_library() command in it that makes a .so library (for x86 it makes a .a library for some reason), I can link my native-lib against that target. I found that these libraries are added to the app/build/intermediates/cmake/obj/${abi} folder (except x86, which for some reason adds it in the fftw_build folder). The linking is done using the target_link_libraries() command show above.

include_directories()命令使fftw3.h文件对项目可见.但是,除非您运行安装命令,否则fftw3.h文件将不会被复制到Android项目中的任何位置. FFTW3 CMakeList.txt文件包含多个安装命令,这些命令在构建期间不会运行.如果运行构建文件夹中的cmake_install.cmake文件,则将执行这些命令.您可以使用include()命令执行此操作.不知道这是否是通常要做的事情,但这就是我发现您可以做到的方式.我没有运行install命令,因为发现它没有必要.

The include_directories() command makes the fftw3.h file visible to the project. However, the fftw3.h file will not be copied anywhere within the Android project, unless you run an install command. The FFTW3 CMakeList.txt file has multiple install commands that don't get run during build time. These commands get executed if the cmake_install.cmake file that is located within the build folder is run. You can do this using the include() command. Not sure if this is what is generally done, but this is how I found you can do it. I did not run the install command because I found it was not necessary.

问题是,我想要单精度,如果我将FFTW3 CMakeList.txt文件中的ENABLE_FLOAT选项设置为ON,我认为我可以得到单精度.如果这样做,并执行上述步骤1-3(同时链接到fftw3f而不是fftw3),则会出现以下错误:

The problem is, I want single precision, which I thought I could get if I just set the ENABLE_FLOAT option in the FFTW3 CMakeList.txt file to ON. If I do that, and do steps 1-3 above (while linking to fftw3f instead of fftw3), I get the following error:

构建命令失败.
执行过程C:\ Users \ reyna \ AppData \ Local \ Android \ Sdk \ cmake \ 3.6.4111459 \ bin \ cmake.exe时出现错误,参数为{--build C:\ Users \ reyna \ Documents \ HMC \ Clinic \ AmazonAppTest \ Test2 \ app.cxx \ cmake \ debug \ armeabi-v7a --target native-lib} [1/1]链接CXX共享库........ \ build \ intermediates \ cmake \ debug \ obj \ armeabi-v7a \ libnative-lib.so 失败:cmd.exe/C"cd.&& C:\ Users \ reyna \ AppData \ Local \ Android \ Sdk \ ndk \ 20.0.5594570 \ toolchains \ llvm \ prebuilt \ windows-x86_64 \ bin \ clang ++.exe --target = armv7-none-linux-androideabi16 --gcc-toolchain = C:/Users/reyna/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64 --sysroot = C:/Users/reyna/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-表-fstack-protector-strong-无规范前缀-fno-addrsig -march = armv7-a -mthumb -Wa,-noexecstack -Wformat -Werror = format-security -O0 -fno-limit-debug-info- Wl,-exclude-libs,libgcc.a -Wl,-exclude-libs,libatomic.a -static-libstdc ++ -Wl,-build-id -Wl,-warn-shared-textrel -Wl,-致命警告-Wl,-排除libs,libunwind.a -Wl,-未定义的-Qunused参数-Wl,-z,noexecstack-共享的-Wl,-soname,libnative-lib.so -o. ....... \ build \ intermediates \ cmake \ debug \ obj \ armeabi-v7a \ libnative-lib.so CMa keFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -lfftw3f ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libAudioEngine .so -llog -landroid ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libCallback.so -llog ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/liboboe.so -latomic -lm&& cd." C:/Users/reyna/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/..../../../arm-linux-androideabi/bin\ld:错误:找不到-lfftw3f

Build command failed.
Error while executing process C:\Users\reyna\AppData\Local\Android\Sdk\cmake\3.6.4111459\bin\cmake.exe with arguments {--build C:\Users\reyna\Documents\HMC\Clinic\AmazonAppTest\Test2\app.cxx\cmake\debug\armeabi-v7a --target native-lib} [1/1] Linking CXX shared library ........\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so FAILED: cmd.exe /C "cd . && C:\Users\reyna\AppData\Local\Android\Sdk\ndk\20.0.5594570\toolchains\llvm\prebuilt\windows-x86_64\bin\clang++.exe --target=armv7-none-linux-androideabi16 --gcc-toolchain=C:/Users/reyna/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64 --sysroot=C:/Users/reyna/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/sysroot -fPIC -g -DANDROID -fdata-sections -ffunction-sections -funwind-tables -fstack-protector-strong -no-canonical-prefixes -fno-addrsig -march=armv7-a -mthumb -Wa,--noexecstack -Wformat -Werror=format-security -O0 -fno-limit-debug-info -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libatomic.a -static-libstdc++ -Wl,--build-id -Wl,--warn-shared-textrel -Wl,--fatal-warnings -Wl,--exclude-libs,libunwind.a -Wl,--no-undefined -Qunused-arguments -Wl,-z,noexecstack -shared -Wl,-soname,libnative-lib.so -o ........\build\intermediates\cmake\debug\obj\armeabi-v7a\libnative-lib.so CMakeFiles/native-lib.dir/src/main/cpp/native-lib.cpp.o -lfftw3f ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libAudioEngine.so -llog -landroid ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/libCallback.so -llog ../../../../build/intermediates/cmake/debug/obj/armeabi-v7a/liboboe.so -latomic -lm && cd ." C:/Users/reyna/AppData/Local/Android/Sdk/ndk/20.0.5594570/toolchains/llvm/prebuilt/windows-x86_64/lib/gcc/arm-linux-androideabi/4.9.x/../../../../arm-linux-androideabi/bin\ld: error: cannot find -lfftw3f

clang ++:错误:链接器命令失败,退出代码为1(使用-v查看调用)

clang++: error: linker command failed with exit code 1 (use -v to see invocation)

忍者:构建停止:子命令失败.

ninja: build stopped: subcommand failed.

推荐答案

我可以使用单精度构建,但是它不是一个很好的解决方案,因为我认为如果我执行"Clean Project"或"Refresh Linked"之类的工作C ++项目"将不再起作用,我将不得不重复下面将描述的过程:

I got the single precision build to work, but its not a great solution, since I think that if I do stuff like "Clean Project" or "Refresh Linked C++ Projects" it will not work anymore and I would have to repeat the process I will describe below:

1)我在问题中指定的CMake参数仍然相同.但是,我进入了FFTW3的CMakeLists.txt,并将ENABLE_FLOAT选项设置为ON.在此过程的这一点上,单精度更改将仅反映到x86 ABI构建中.因此,当我尝试构建项目时,Android Studio会抱怨找不到为armeabi-v7a构建的fftw3f库.
2)我想到了之前需要为每个ABI构建FFTW3的想法,因此我在defaultConfig {}中的build.gradle文件中添加了以下内容:

1) The CMake arguments that I specified in the question are still the same. However, I went into the CMakeLists.txt of FFTW3 and set the ENABLE_FLOAT option to ON. At this point in the process, the single precision change would only be reflected for the x86 ABI build. So, when I tried to build the project, Android Studio would complain about not finding the fftw3f library for the armeabi-v7a build.
2) I went with an idea I had seen before that we needed to build FFTW3 for each ABI, so I added the following to my build.gradle file inside of defaultConfig{}:

externalNativeBuild {
            cmake {
                arguments "-DANDROID_ABI=x86_64"
                abiFilters "armeabi-v7a", "arm64-v8a", "x86", "x86_64"

            }
            ndk {
                abiFilters 'armeabi-v7a', 'arm64-v8a', 'x86', 'x86_64'

            }

将-DANDROID_ABI标志更改为要构建的ABI的位置.我真的不确定是否需要abiFilters东西,但是我很自信需要参数标志.我目前已注释掉abiFilter的内容,因为在将应用程序安装到手机中后,由于找不到我的本机库,会出现错误.
3)我用每个ABI标志构建了Android项目,这有点麻烦,所以也许我需要做

where I would change the -DANDROID_ABI flag to the ABI I wanted to build. I am really not sure whether the abiFilters stuff is needed or not, but I'm pretty confident that the argument flag is needed. I currently have commented out the abiFilter stuff because I would get errors after installing my app into my phone about not finding my native-lib.
3) I built the Android Project with each ABI flag, which is kind of a hassle, so maybe I would need do the build multiple apks method.

这篇关于如何使用CMAKE将FFTW添加到Android项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆