我使用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 /主/ 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
{
谢谢!的
答案 0 :(得分:0)
将傻瓜 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 "Directory to find SSBA libs")
link_directories(${SSBA_LIBRARY_DIR})
include_directories(${SSBA_LIBRARY_DIR}/../)