我正在运行 Ubuntu 18。我想将我编写的 c++ 脚本转换为 android 应用程序。我看到 Android 应用程序也可以运行 c++ 脚本。我的脚本依赖于 PCL(点云库)、CGAL 和 TBB。作为第一步,我想确保我可以在 android studio 中制作一个依赖于 PCL 的 c++ 脚本。我按照本教程创建了一个使用简单 c++ 脚本的 android 应用程序。接下来我想在该脚本中使用点云库。作为第一步,我修改了 CMakeList.txt,这就是问题开始的地方......
目前我的 CMakeList.txt 文件如下所示:
# For more information about using CMake with Android Studio, read the
# documentation: https://d.android.com/studio/projects/add-native-code.html
# Sets the minimum version of CMake required to build the native library.
cmake_minimum_required(VERSION 3.4.1)
# Declares and names the project.
project("cmaketest")
# Creates and names a library, sets it as either STATIC
# or SHARED, and provides the relative paths to its source code.
# You can define multiple libraries, and CMake builds them for you.
# Gradle automatically packages shared libraries with your APK.
add_library( # Sets the name of the library.
native-lib
# Sets the library as a shared library.
SHARED
# Provides a relative path to your source file(s).
native-lib.cpp )
# Searches for a specified prebuilt library and stores the path as a
# variable. Because CMake includes system libraries in the search path by
# default, you only need to specify the name of the public NDK library
# you want to add. CMake verifies that the library exists before
# completing its build.
find_library( # Sets the name of the path variable.
log-lib
# Specifies the name of the NDK library that
# you want CMake to locate.
log )
# Specifies libraries CMake should link to your target library. You
# can link multiple libraries, such as libraries you define in this
# build script, prebuilt third-party libraries, or system libraries.
set(PCL_DIR "/usr/lib/x86_64-linux-gnu/cmake/pcl")
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} ${PCL_LIBRARIES})
我已经用这个例子验证了我的 PCL 安装,一切正常。这是用于验证的 CMakeList.txt:
cmake_minimum_required(VERSION 2.8 FATAL_ERROR)
project(pcd_write)
find_package(PCL 1.2 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable (pcd_write pcd_write.cpp)
target_link_libraries (pcd_write ${PCL_LIBRARIES})
但在 Android Studio 中,我收到一个错误,即找不到 eigen:
Execution failed for task ':app:generateJsonModelDebug'.
> error when building with cmake using /home/dan/AndroidStudioProjects/CmakeTest/app/src/main/cpp/CMakeLists.txt: Build command failed.
Error while executing process /home/dan/Android/Sdk/cmake/3.6.4111459/bin/cmake with arguments {-H/home/dan/AndroidStudioProjects/CmakeTest/app/src/main/cpp -DCMAKE_CXX_FLAGS=-std=c++17 -DCMAKE_FIND_ROOT_PATH=/home/dan/AndroidStudioProjects/CmakeTest/app/.cxx/cmake/debug/prefab/x86/prefab -DCMAKE_BUILD_TYPE=Debug -DCMAKE_TOOLCHAIN_FILE=/home/dan/Android/Sdk/ndk/21.4.7075529/build/cmake/android.toolchain.cmake -DANDROID_ABI=x86 -DANDROID_NDK=/home/dan/Android/Sdk/ndk/21.4.7075529 -DANDROID_PLATFORM=android-19 -DCMAKE_ANDROID_ARCH_ABI=x86 -DCMAKE_ANDROID_NDK=/home/dan/Android/Sdk/ndk/21.4.7075529 -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=/home/dan/AndroidStudioProjects/CmakeTest/app/build/intermediates/cmake/debug/obj/x86 -DCMAKE_RUNTIME_OUTPUT_DIRECTORY=/home/dan/AndroidStudioProjects/CmakeTest/app/build/intermediates/cmake/debug/obj/x86 -DCMAKE_MAKE_PROGRAM=/home/dan/Android/Sdk/cmake/3.6.4111459/bin/ninja -DCMAKE_SYSTEM_NAME=Android -DCMAKE_SYSTEM_VERSION=19 -B/home/dan/AndroidStudioProjects/CmakeTest/app/.cxx/cmake/debug/x86 -GNinja}
-- Could NOT find eigen (missing: EIGEN_INCLUDE_DIRS)
-- Configuring incomplete, errors occurred!
See also "/home/dan/AndroidStudioProjects/CmakeTest/app/.cxx/cmake/debug/x86/CMakeFiles/CMakeOutput.log".
* 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.
我不明白为什么 pcl 可以在常规项目中找到,但不能在 android studio 项目中找到,因为我在 CMakeList.txt 中使用了相同的行?CMakeList.txt 文件在 Android Studio 中的处理方式是否存在差异?我还必须为我的 pcl 库添加一个直接路径,以便它使用 Android Studio 找到 pcl,这在常规项目中是不需要的。(我用这条线做到了set(PCL_DIR "/usr/lib/x86_64-linux-gnu/cmake/pcl")
:)
有任何想法吗?
谢谢!
丹尼尔