【发布时间】:2018-11-03 02:02:22
【问题描述】:
我使用 cmake 在 Android Studio 中构建 C++ 源文件。 我想导入 SSBA-4.0 库,但我是 Cmake 新手
完全错误:
C:\Users\usrname\AndroidProjects\myproject\app\src\main\cpp\SSBA-4.0\Math\v3d_optimization.cpp:1:10: fatal error: 'Math/v3d_optimization.h' file not found
#include "Math/v3d_optimization.h"
^~~~~~~~~~~~~~~~~~~~~~~~~
我的 /CMakeList.txt 使用add_subdirectory(src/main/cpp/SSBA-4.0) 指向库:
# 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)
# OpenCV IMPORT
include_directories(C:/OpenCV_android_sdk_3_0/sdk/native/jni/include)
add_library( lib-opencv SHARED IMPORTED )
set_target_properties(lib-opencv PROPERTIES IMPORTED_LOCATION ${CMAKE_SOURCE_DIR}/src/main/jniLibs/${ANDROID_ABI}/libopencv_java.so)
# 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).
src/main/cpp/native-lib.cpp
src/main/cpp/main.cpp
src/main/cpp/Distance.h
src/main/cpp/Distance.cpp
src/main/cpp/Triangulation.cpp
src/main/cpp/Triangulation.h
src/main/cpp/FindCameraMatrices.cpp
src/main/cpp/FindCameraMatrices.h
src/main/cpp/MultiCameraDistance.cpp
src/main/cpp/MultiCameraDistance.h
src/main/cpp/IDistance.h
src/main/cpp/MultiCameraPnP.cpp
src/main/cpp/MultiCameraPnP.h
src/main/cpp/Common.cpp
src/main/cpp/Common.h
src/main/cpp/IFeatureMatcher.h
src/main/cpp/RichFeatureMatcher.cpp
src/main/cpp/RichFeatureMatcher.h
src/main/cpp/OFFeatureMatcher.cpp
src/main/cpp/OFFeatureMatcher.h
src/main/cpp/BundleAdjuster.cpp
src/main/cpp/BundleAdjuster.h
src/main/cpp/GPUSURFFeatureMatcher.cpp
src/main/cpp/GPUSURFFeatureMatcher.h
src/main/cpp/AbstractFeatureMatcher.cpp
src/main/cpp/AbstractFeatureMatcher.h
src/main/cpp/SfMUpdateListener.cpp
src/main/cpp/SfMUpdateListener.h
)
# 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.
target_link_libraries( # Specifies the target library.
native-lib
# Links the target library to the log library
# included in the NDK.
${log-lib} )
add_subdirectory(src/main/cpp/SSBA-4.0)
src/main/cpp/SSBA-4.0/CMakeList.txt:
cmake_minimum_required(VERSION 2.6)
project(V3D)
set (V3D_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set (V3D_INCLUDE_DIRS ${V3D_DIR}/.)
include (Config/v3d_macros.cmake)
include (Config/local_config.cmake)
include_directories(${V3D_INCLUDE_DIRS} ${EXTRA_INC_DIRS})
source_group("Base" REGULAR_EXPRESSION Base/.*cpp|Base.*h)
set (BASE_SRC
Base/v3d_exception.h
Base/v3d_serialization.h
Base/v3d_vrmlio.h
)
if (V3DLIB_ENABLE_SOCKETS)
set (BASE_SRC ${BASE_SRC} Base/v3d_socket.h)
endif (V3DLIB_ENABLE_SOCKETS)
source_group("Math" REGULAR_EXPRESSION Math/.*cpp|Math.*h)
set (MATH_SRC
Math/v3d_linear.h
Math/v3d_linearbase.h
Math/v3d_mathutilities.h
Math/v3d_nonlinlsq.h
Math/v3d_nonlinlsq.cpp
Math/v3d_optimization.h
Math/v3d_optimization.cpp
Math/v3d_optimization_lm.cpp
)
source_group("Geometry" REGULAR_EXPRESSION Geometry/.*cpp|Geometry.*h)
set (GEOMETRY_SRC
Geometry/v3d_cameramatrix.h
Geometry/v3d_distortion.h
Geometry/v3d_metricbundle.h
Geometry/v3d_metricbundle.cpp
Geometry/v3d_stereobundle.h
Geometry/v3d_stereobundle.cpp
)
source_group("Dependencias" REGULAR_EXPRESSION Dependencias/.*cpp|Dependencias.*h)
set (DEPENDENCIAS_SRC
Dependencias/colamd.h
Dependencias/colamd.c
Dependencias/UFConfig.h
Dependencias/colamd_global.c
)
set (ALL_SRC
${BASE_SRC} ${MATH_SRC} ${GEOMETRY_SRC} ${GL_SRC} ${CUDA_SRC} ${DEPENDENCIAS_SRC}
)
add_library(V3D ${ALL_SRC})
add_subdirectory(Apps)
v3d_optimization.h的文件路径为src/main/cpp/SSBA-4.0/Math/v3d_optimization.h
这是 v3d_optimization.cpp 标头,错误来自:
#include "Math/v3d_optimization.h"
#if defined(V3DLIB_ENABLE_SUITESPARSE)
//# include "COLAMD/Include/colamd.h"
# include "Dependencias/colamd.h"
# if 0
extern "C"
{
//# include "LDL/Include/ldl.h"
# include "ldl.h"
}
# else
# include "Math/v3d_ldl_private.h"
# endif
#endif
#define USE_BLOCK_REORDERING 1
//#define USE_MULTIPLICATIVE_UPDATE 1
#include <iostream>
#include <map>
using namespace std;
namespace V3D
{
谢谢!
【问题讨论】:
-
不同,因为错误来自 os SSBA 库内部,当您在我的项目外部编译它时运行完美(仅 SSBA-4.0/CMakeList.txt)......我没有改变了来源。用 v3d_optimization.cpp 标头更新了我的帖子。
-
"...当您在我的项目之外编译它时运行完美(仅 SSBA-4.0/CMakeList.txt)" - 但在您的情况下,您不要使用
SSBA-4.0/CMakeList.txt。相反,您手动(使用add_library调用)从源文件构建 SSBA 库。所以你应该添加适当的包含目录来编译这些源代码。 -
工作将傻瓜 src/main/cpp/SSBA-4.0 移动到 src/main/SSBA-4.0 并使用以下行导入 /CMakeList.txt: set(SSBA_LIBRARY_DIR "${CMAKE_SOURCE_DIR}/. ./SSBA-4.0/build" CACHE PATH "查找 SSBA 库的目录") link_directories( ${SSBA_LIBRARY_DIR} ) link_directories(${SSBA_LIBRARY_DIR}) include_directories(${SSBA_LIBRARY_DIR}/../)
标签: c++ android-studio opencv cmake