【解决问题】fatal error: cs.h: No such file or directory

博客的运行环境为Ubuntu 18.04 。

在编译slam相关的代码PnP的相关文件时遇到如下错误。
fatal error: cs.h: No such file or directory
#include <cs.h>

解决方案

1、先把Home/g2o/g2o/solvers/csparse路径下的cmake_modules文件夹复制到你的工程文件夹下。
在这里插入图片描述

2、修改一下你运行项目的CMakeLists.txt文件。
pose_estimation_3d2d.cpp是我的cpp文件;PnP是我的编译文件。注意一定要确保修改正确!

cmake_minimum_required(VERSION 2.8)

project(pose_estimation_3d2d)
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
set(CMAKE_CXX_STANDARD 11)
SET( G2O_ROOT /usr/local/include/g2o )
find_package( OpenCV REQUIRED )
find_package(Eigen3  REQUIRED)
find_package(G2O REQUIRED)
find_package( CSparse)
include_directories(
${EIGEN3_INCLUDE_DIR}
${OpenCV_INCLUDE_DIRS}
${G2O_INCLUDE_DIRS} 
${CSPARSE_INCLUDE_DIR} 
)

add_executable(PnP pose_estimation_3d2d.cpp)

target_link_libraries( PnP ${OpenCV_LIBS})
target_link_libraries( PnP ${EIGEN3_LIB} ${OpenCV_LIBS} ${G2O_LIB} ${CSPARSE_LIB})
target_link_libraries( PnP g2o_core g2o_stuff)

3、然后再次编译运行就好啦。
命令分别对应:编译文件、图片1、图片2、灰度图。

./PnP image1 image 2 depth1
原创文章 41 获赞 65 访问量 8361

猜你喜欢

转载自blog.csdn.net/weixin_44436677/article/details/106095485