1 介绍
CMakeLists.txt模板
#声明要求的cmake最低版本
cmake_minimum_required(VERSION 3.10)
#设置c++版本
set(CMAKE_CXX_STANDARD 11)
#声明一个cmake工程
project("Hello world")
#添加头文件
include_directories("库头文件名")
find_package(库名 REQUIRED)
#find_package命令是cmake提供的寻找某个库的头文件与库文件的指令。如果cmake能够找到它,就会提供头文件和库文件所在的目录的变量,一般为库名_DIRECTORIES和库名_LIBRARIES。
include_directories( ${库名_DIRECTORIES} )
#添加可执行程序
add_executable(main main.cpp)
#把可执行程序链接到库文件上
target_link_libraries(main ${库名_LIBRARIES})
常用库头文件添加和库文件链接
#Eigen库是一个仅由头文件组成的库,所以只需添加头文件即可,而无需链接到库文件
include_directories("/usr/include/eigen3")
#OpenCV
#添加OpenCV的头文件
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_DIRECTORIES})
#链接OpenCV的库文件
target_link_libraries(main ${OpenCV_LIBRARIES})
#Sophus也是仅由头文件组成的库
find_package(Sophus REQUIRED)
include_directories(${Sophus_DIRECTORIES})
#Pangolin
#添加头文件
find_package(Pangolin REQUIRED)
include_directories(${Pangolin_DIRECTORIES})
#链接库文件
target_link_libraries(main ${Pangolin_LIBRARIES})
#jsoncpp
#添加头文件
include_directories(
"/usr/include/jsoncpp/"
)
#链接库文件
target_link_libraries(READ_TOPO_GEOJSON
"/usr/lib/x86_64-linux-gnu/libjsoncpp.so"
)
#fmt
#添加头文件
find_package(fmt REQUIRED)
include_directories(${FMT_DIRECTORIES})
#链接库文件
arget_link_libraries(render_anp3_topomap
fmt::fmt
)
调用头文件
//Eigen头文件
#include <Eigen/Core>
#include <Eigen/Dense>
#include <Eigen/Geometry>
//OpenCV头文件
#include <opencv2/core.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/xfeatures2d.hpp>
#include <opencv2/highgui.hpp>
//Sophus头文件
#include "sophus/se3.hpp"
//Pangolin头文件
#include <pangolin/pangolin.h>
2 训练
cmake_minimum_required(VERSION 3.0)
project(render_anp3_topomap)
set(CMAKE_CXX_STANDARD 17)
set(CYBERTRONREADER_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rd_party/CybertronReader/include)
set(PROTOBUF_INCLUDE_DIR ${CMAKE_SOURCE_DIR}/3rd_party/protobuf/include)
set(PROTOBUF_LIBRARIES ${CMAKE_SOURCE_DIR}/3rd_party/protobuf/lib/libprotobuf.so)
find_package(OpenCV REQUIRED)
include_directories(
"/usr/include/jsoncpp"
)
include_directories(${OpenCV_DIRECTORIES})
include_directories(${PROTOBUF_INCLUDE_DIR})
include_directories(
${CMAKE_SOURCE_DIR}/proto_hpp
)
include_directories(${CYBERTRONREADER_INCLUDE_DIR})
file(GLOB SOURCES ${CMAKE_SOURCE_DIR}/proto_hpp/*.cc)
file(GLOB CYBERTRONREADER_LIBRARIES ${CMAKE_SOURCE_DIR}/3rd_party/CybertronReader/lib/*)
add_executable(render_anp3_topomap src/anp3_topomap_jingjian.cpp ${SOURCES})
target_link_libraries(render_anp3_topomap
${CYBERTRONREADER_LIBRARIES}
"/usr/lib/x86_64-linux-gnu/libjsoncpp.so"
${OpenCV_LIBRARIES}
${PROTOBUF_LIBRARIES}
)