使用Cmake设置库

时间:2016-06-24 14:48:12

标签: c++ cmake

我有一个项目文件夹MultiViewReconstruction,它有三个子文件夹STM,V3D,Visualization。

-MultiViewReconstruction
   -STM
   -V3D
   -Visualization

MultiViewReconstruction中的CMakeLists.txt是

cmake_minimum_required(VERSION 2.6)

PROJECT(MultiViewReconstruction)
# The version number.
set (VERSION_MAJOR 1)
set (VERSION_MINOR 0)
# configure a header file to pass some of the CMake settings
# should we use our own math functions?
option (FILES 
        "Use tutorial provided math implementation" ON) 
option (VIDEO 
        "Use tutorial provided math implementation" OFF)
option (CAMERA 
        "Use tutorial provided math implementation" OFF)  
# to the source code
configure_file (
  "${PROJECT_SOURCE_DIR}/Config.h.in"
  "${PROJECT_BINARY_DIR}/Config.h"
)

include_directories("${PROJECT_BINARY_DIR}")

# Linked libariries
#For Opencv
find_package( OpenCV REQUIRED )
#For PCL
find_package(PCL 1.3 REQUIRED)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
#Additional libraries
include_directories ("${PROJECT_SOURCE_DIR}/STM")
add_subdirectory (STM)
include_directories ("${PROJECT_SOURCE_DIR}/Visualization")
add_subdirectory (Visualization)
include_directories("${PROJECT_SOURCE_DIR}/V3D")
add_subdirectory (V3D)

set (EXTRA_LIBS ${EXTRA_LIBS} STM  Visualization V3D)


ADD_EXECUTABLE(MultiViewReconstruction MultiViewReconstruction.cpp)
target_link_libraries(MultiViewReconstruction ${OpenCV_LIBS}; ${PCL_LIBRARIES}; ${EXTRA_LIBS}; pthread)

# add the install targets
install (TARGETS MultiViewReconstruction DESTINATION bin)
install (FILES "${PROJECT_BINARY_DIR}/Config.h" DESTINATION include)

STM中的CMakeLists.txt是

add_library(STM STM.cpp FeatureMatching.cpp Triangulation.cpp Common.cpp BundleAdjuster.cpp)

install (TARGETS STM DESTINATION bin)
install (FILES STM.h FeatureMatching.h Triangulation.h Common.h BundleAdjuster.h DESTINATION include)

Visualization中的CMakeLists.txt是

add_library(Visualization Visualization.cpp)
install (TARGETS Visualization DESTINATION bin)
install (FILES Visualization.h DESTINATION include)

V3D内的CMakeLists.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)


file(   GLOB COLAMD_SRC 
    COLAMD/Source/* 
    COLAMD/Include/* 
    SuiteSparse_config/SuiteSparse_config.h 
    SuiteSparse_config/SuiteSparse_config.c
    )
include_directories("SuiteSparse_config/")
add_library(colamd ${COLAMD_SRC})
set ( V3D_INCLUDE_DIRS ${V3D_INCLUDE_DIRS} "COLAMD/Include" )



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
)

set (ALL_SRC
    ${BASE_SRC} ${MATH_SRC} ${GEOMETRY_SRC} ${GL_SRC} ${CUDA_SRC}
)

add_library(V3D ${ALL_SRC})
add_subdirectory(Apps)

当我构建时,我有错误

In file included from /home/Softwares/3D_images/MultiViewReconstruction/STM/BundleAdjuster.cpp:44:0:
/home/Softwares/3D_images/MultiViewReconstruction/STM/../V3D/Math/v3d_linear.h:6:33: fatal error: Math/v3d_linearbase.h: No such file or directory
 #include "Math/v3d_linearbase.h"
                                 ^
compilation terminated.
make[2]: *** [STM/CMakeFiles/STM.dir/BundleAdjuster.cpp.o] Error 1
make[1]: *** [STM/CMakeFiles/STM.dir/all] Error 2
make: *** [all] Error 2

编辑:

BundleAdjuster.cpp has
#include "../V3D/Math/v3d_linear.h"


v3d_linear.h has
#include "Math/v3d_linearbase.h"
v3d_linear.h and v3d_linearbase.h are in the same Math folder. 

但找不到对方

在链接库时我在哪里犯错误?

由于

0 个答案:

没有答案