Ceres Solver配置测试代码运行环境

设置测试环境的目录为Ceres_Example

1.配置ceres库

1.编译动态库,将之放到Ceres_Example/lib/中

2.整理头文件,将下载的ceres库只保留头文件,放到Ceres_Example/3rdparty/中

3.下载所需的Eigen库,放到Ceres_Example/3rdparty/中

2.编写CMakeLists.txt

cmake_minimum_required (VERSION 3.0)

# 本CMakeLists.txt的project名称
# 会自动创建两个变量,PROJECT_SOURCE_DIR和PROJECT_NAME
# ${PROJECT_SOURCE_DIR}:本CMakeLists.txt所在的文件夹路径
# ${PROJECT_NAME}:本CMakeLists.txt的project名称
project(ceres_test)
# 添加c++ 11标准支持
set( CMAKE_CXX_FLAGS "-std=c++11" )

# 如果想要生成的可执行文件拥有符号表,可以gdb调试,就直接加上这句
add_definitions("-Wall -g")

set(CERES_INCLUDE_DIRS "${PROJECT_SOURCE_DIR}/3rdparty"
                       "${PROJECT_SOURCE_DIR}/3rdparty/ceres/include"
                       "${PROJECT_SOURCE_DIR}/3rdparty/ceres/config"
                       "${PROJECT_SOURCE_DIR}/3rdparty/ceres/internal/ceres/miniglog"
)

include_directories (
  ${CMAKE_SOURCE_DIR}
  ${CERES_INCLUDE_DIRS}
)
LINK_DIRECTORIES("${PROJECT_SOURCE_DIR}/lib/")
LINK_LIBRARIES(ceres)

add_executable (ceres_test ceres_test.cpp ceres_test.h)

3.创建测试文件
ceres_test.cpp
ceres_test.h
代码为ceres测试实例

4.编译

$ cd Ceres_Example
$ cmake ..
$ make
# 执行
$ ./ceres_test

PS:问题
需要在ceres/include/ceres/internal/config.h手动添加代码

#define CERES_USE_CXX11_THREADS
posted on 2021-09-24 13:05  JJ_S  阅读(691)  评论(0编辑  收藏  举报