SLAM14讲,Sophus使用,Find_Package()无法定位

ch4的示例代码,拿出来测试,总是出现如下错误:

SLAM/demo/ch4/src/useSophus.cpp:5:10: fatal error: sophus/se3.hpp: 没有那个文件或目录
 #include "sophus/se3.hpp"
          ^~~~~~~~~~~~~~~~

这时CMakeLists.txt中是这样的:

#需要使用find_package命令找到它
find_package(Sophus REQUIRED)
include_directories(${Sophus_INCLUDE_DIRS})

我想显示${Sophus_INCLUDE_DIRS},于是加了一句:MESSAGE()如下所示:

#需要使用find_package命令找到它
find_package(Sophus REQUIRED)
include_directories(${Sophus_INCLUDE_DIRS})

message(STATUS "Include_directories: " ${Sophus_INCLUDE_DIRS})

之后Cmake结果是:

xj@xj-MRC-WX0:~/SLAM/demo/ch4/build$ cmake ..
-- Include_directories: 
-- Configuring done
-- Generating done
-- Build files have been written to: /home/xj/SLAM/demo/ch4/build

可见,根本就没有正确的include路径,于是只能指定绝对路径了,完整的CMakeLists.txt为:

#需要使用find_package命令找到它
#find_package(Sophus REQUIRED)
#include_directories(${Sophus_INCLUDE_DIRS})
include_directories("/home/xj/SLAM/3rdparty/Sophus/sophus")
message(STATUS "Include_directories: " ${Sophus_INCLUDE_DIRS})

# Eigen
include_directories("/usr/include/eigen3")
add_executable(useSophus useSophus.cpp)

注意,因为指定到了..Sophus/sophus,所以源码中的useSophus.cpp也要改一下:

#include "sophus/se3.hpp"

改成 :

#include "se3.hpp"

结果就没有问题了:

xj@xj-MRC-WX0:~/SLAM/demo/ch4/build$ make
Scanning dependencies of target useSophus
[ 50%] Building CXX object src/CMakeFiles/useSophus.dir/useSophus.cpp.o
[100%] Linking CXX executable useSophus
[100%] Built target useSophus

总结一下:之前以为是Sophus没有编译(build)好,各种试,原来只是Include没有find,为什么?先不深究了,赶进度测试学习。

 


版权声明:本文为xujie126原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。