VSLAM依赖库版本配置(CMake)

本文详细介绍了在开发VSLAM程序时,如何配置和选择OpenCV、g2o、eigen3等关键依赖库的方法。针对不同开源程序的版本需求,提供了具体的安装与使用步骤,帮助开发者避免版本冲突,实现高效开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

在开发VSLAM程序的过程中,我需要不断地学习开源程序,如ORB-SLAM2、SVO、LSD-SLAM、DSO、LearnVIORB、ygz-stereo-inertial、svo_degelet、ORB-TGZ-SLAM等等,其中依赖的库较多,主要的有OpenCV、g2o、eigen3、Sophus等。

不同的程序使用的版本往往不一样,由于需要学习不同的开源程序并转化为自己的知识,进而开发自己的 程序,因此,无法在ubuntu系统中安装一个版本适应所有开源程序。因此,需要配置选择安装于系统之外的依赖库,本博客暂时介绍OpenCV、g2o、eigen3的配置选择方法。

1 OpenCV

1.1 安装OpenCV时

注意使用-D CMAKE_INSTALL_PREFIX设置安装路径。

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/somepath/local ..

to build with modules from opencv_contrib set OPENCV_EXTRA_MODULES_PATH to <path to opencv_contrib/modules/>

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/somepath/local -D OPENCV_EXTRA_MODULES_PATH=/somepath/opencv_contrib/modules/ ..

示例:

cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/home/huicanlin/Downloads/software/opencv-3.2.0/local -D OPENCV_EXTRA_MODULES_PATH=/home/huicanlin/Downloads/software/opencv-3.2.0/opencv_contrib-3.2.0/modules/ ..

 

1.2 配置VSLAM程序CMakeLists.txt

在FIND_PACKAGE()之前,设置OpenCV_DIR,如下所示:

set(OpenCV_DIR "/home/huicanlin/Downloads/software/opencv-2.4.13.5/local/share/OpenCV/")#huicanlin
FIND_PACKAGE(OpenCV REQUIRED)

2 g2o

2.1安装g2o时

cd workspace
git clone https://github.com/RainerKuemmerle/g2o.git
cd g2o
mkdir build
cd build
cmake ..
make
sudo make install

If you don't want to make a system install, then you can replace the cmake command with 

cmake .. -DCMAKE_INSTALL_PREFIX:PATH=$HOME/installdir

例如在2.2时,我是这么做的:

cmake .. -DCMAKE_INSTALL_PREFIX:PATH=../local

 

2.2使用g2o时

在FIND_PACKAGE()之前,设置G2O_ROOT,如下所示:

set(G2O_ROOT "/home/huicanlin/src/svo_edgelet/Thirdparty/g2o/local/")#$HOME/installdir
FIND_PACKAGE(G2O REQUIRED)

可能需要如下操作,才能生效:

cd ..
rm -r build
mkdir build
cd build
cmake ..

2.3 碰到问题

在调试高翔的slambook的ch10的g2o_custombundle的时候,原CMakeLists.txt关于g2o的配置:

set(G2O_ROOT "/home/huicanlin/src/slambook/3rdparty/g2o/local/") # huicanlin added.
Find_Package(G2O REQUIRED)
include_directories( ${G2O_INCLUDE_DIR} ) # huicanlin added. SET(G2O_LIBS ... g2o_core
g2o_interface ...)
target_link_libraries(... ${G2O_LIBS} ...)
make的时候,有个.h文件找不到.
因此在Find_Package()下面,加了如上所示的一行;为了与高翔提供的g2o版本一致,又在Find_Package()上面,加了如上所示的1行.make能够通过。
但是,运行的时候出现错误:Segmentation fault,在gdb中调试,发现问题来自:/opt/ros/indigo/lib/libg2o_core.so.

我分析错误在于“SET(G2O_LIBS ... g2o_core g2o_interface ...)”的时候,其实指向了ROS下的.so文件,也就是说,include的是Find_Package()找到的文件,但是库文件却是ROS下的。若是版本不同,容易出现错误。

修改方法:
将g2o_core改为${G2O_CORE_LIBRARY}
SET(G2O_LIBS ... ${G2O_CORE_LIBRARY} g2o_interface ...)

然后重新编译:

rm -r /build
cd build
cmake ..
make -j4

再次运行就没问题了。

 

3 eigen3

3.1 安装时

cmake .. -DCMAKE_INSTALL_PREFIX:PATH=../local

3.2 使用时

#set(EIGEN3_INCLUDE_DIR "/home/huicanlin/Downloads/software/eigen-3.2.10/local/include/eigen3/")
find_package(Eigen3 REQUIRED)

 

以下4-7为编译S-PTAM时需要的依赖:

4 DBow2

4.1安装

git clone git@github.com:dorian3d/DBoW2.git

Tested until commit 82401cad2cfe7aa28ee6f6afb01ce3ffa0f59b44

git checkout 82401cad2cfe7aa28ee6f6afb01ce3ffa0f59b44

mkdir build

cd build

cmake .. -DCMAKE_INSTALL_PREFIX:PATH=../local

make -j4

make install

4.2 使用

set(DBoW2_DIR "../../Thirdparty/DBoW2/build") #DBoW2Config.cmake,其它路径,有此文件即可
find_package(DBoW2 REQUIRED)

5 Dlib

5.1 安装

git clone git@github.com:dorian3d/DLib.git
Tested until commit 70089a38056e8aebd5a2ebacbcb67d3751433f32
git checkout 70089a38056e8aebd5a2ebacbcb67d3751433f32
mkidr build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=../local
make -j4
make install

5.2 使用

set(DLib_DIR "../../Thirdparty/DLib/build") #DLibConfig.cmake,其它路径,有此文件即可
find_package(DLib REQUIRED)

6 DLoopDetector

6.1安装

git clone git@github.com:dorian3d/DLoopDetector.git
Tested until commit 8e62f8ae84d583d9ab67796f779272b0850571ce
git checkout 8e62f8ae84d583d9ab67796f779272b0850571ce
mkidr build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=../local
make -j4
make install

 

6.2 使用

set(DLoopDetector_DIR "../../Thirdparty/DLoopDetector/build") #huicanlin
find_package(DLoopDetector REQUIRED)

 

7 opengv

7.1 安装

git clone git@github.com:laurentkneip/opengv.git
Tested until commit 2e2d21917fd2fb75f2134e6d5be7a2536cbc7eb1
git checkout 2e2d21917fd2fb75f2134e6d5be7a2536cbc7eb1
mkidr build
cd build
cmake .. -DCMAKE_INSTALL_PREFIX:PATH=../local
make -j4
make install

7.2 使用

set(OPENGV_ROOT "/home/huicanlin/catkin_ws/src/sptam/Thirdparty/g2o/local/")#$HOME/installdir
find_package(OpenGV REQUIRED)

 

8 gtsam

8.1 安装

源码使用高翔的slambook/3rdparty/gtsam

cmake .. -DCMAKE_INSTALL_PREFIX:PATH=/home/huicanlin/src/slambook/3rdparty/gtsam/local/

make -j4

make install

注意:安装路径必须时绝对路径,否则会报错!

8.2 使用

使用示例,高翔的slambook/ch11:

注意:前两行是我在cmake ..的时候,根据Terminal报错的提示增加的,如此才能够编译通过。

set(GTSAM_DIR "/home/huicanlin/src/slambook/3rdparty/gtsam/local/lib/cmake/GTSAM/") # huicanlin set(GTSAMCMakeTools_DIR "/home/huicanlin/src/slambook/3rdparty/gtsam/local/lib/cmake/GTSAMCMakeTools/") # huicanlin find_package( GTSAMCMakeTools ) find_package( GTSAM REQUIRED ) include_directories( ${GTSAM_INCLUDE_DIR} )

 

 

 

Find_Package(G2O REQUIRED)

转载于:https://www.cnblogs.com/huicanlin/p/8232412.html

Make Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. -- The C compiler identification is GNU 7.5.0 -- The CXX compiler identification is GNU 7.5.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done Build type: Release -- Performing Test COMPILER_SUPPORTS_CXX11 -- Performing Test COMPILER_SUPPORTS_CXX11 - Success -- Performing Test COMPILER_SUPPORTS_CXX0X -- Performing Test COMPILER_SUPPORTS_CXX0X - Success -- Using flag -std=c++11. -- Found OpenCV: /usr/local (found suitable version "4.2.0", minimum required is "4.2") OPENCV VERSION: 4.2.0 CMake Warning at CMakeLists.txt:43 (find_package): By not providing "Findrealsense2.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "realsense2", but CMake did not find one. Could not find a package configuration file provided by "realsense2" with any of the following names: realsense2Config.cmake realsense2-config.cmake Add the installation prefix of "realsense2" to CMAKE_PREFIX_PATH or set "realsense2_DIR" to a directory containing one of the above files. If "realsense2" provides a separate development package or SDK, be sure it has been installed. CMake Error at CMakeLists.txt:116 (add_subdirectory): add_subdirectory given source "Thirdparty/g2o" which is not an existing directory. -- Configuring incomplete, errors occurred! See also "/home/robot/XTDrone/sensing/slam/vslam/ORB_SLAM3/build/CMakeFiles/CMakeOutput.log". make: *** 没有指明目标并且找不到 makefile。 停止。 ./build.sh: 第 9 行: cd: ../../g2o: 没有那个文件或目录 Configuring and building Thirdparty/g2o ... CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. Build type: Release -- Using flag -std=c++11. OPENCV VERSION: 4.2.0 CMake Warning at CMakeLists.txt:43 (find_package): By not providing "Findrealsense2.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "realsense2", but CMake did not find one. Could not find a package configuration file provided by "realsense2" with any of the following names: realsense2Config.cmake realsense2-config.cmake Add the installation prefix of "realsense2" to CMAKE_PREFIX_PATH or set "realsense2_DIR" to a directory containing one of the above files. If "realsense2" provides a separate development package or SDK, be sure it has been installed. CMake Error at CMakeLists.txt:116 (add_subdirectory): add_subdirectory given source "Thirdparty/g2o" which is not an existing directory. -- Configuring incomplete, errors occurred! See also "/home/robot/XTDrone/sensing/slam/vslam/ORB_SLAM3/build/CMakeFiles/CMakeOutput.log". make: *** 没有指明目标并且找不到 makefile。 停止。 ./build.sh: 第 18 行: cd: ../../Sophus: 没有那个文件或目录 Configuring and building Thirdparty/Sophus ... CMake Error: The source directory "/home/robot/XTDrone/sensing/slam/vslam/ORB_SLAM3/build/build" does not appear to contain CMakeLists.txt. Specify --help for usage, or press the help button on the CMake GUI. make: *** 没有指明目标并且找不到 makefile。 停止。 Uncompress vocabulary ... Configuring and building ORB_SLAM3 ... mkdir: 无法创建目录"build": 文件已存在 CMake Deprecation Warning at CMakeLists.txt:1 (cmake_minimum_required): Compatibility with CMake < 2.8.12 will be removed from a future version of CMake. Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions. Build type: Release -- Using flag -std=c++11. OPENCV VERSION: 4.2.0 CMake Warning at CMakeLists.txt:43 (find_package): By not providing "Findrealsense2.cmake" in CMAKE_MODULE_PATH this project has asked CMake to find a package configuration file provided by "realsense2", but CMake did not find one. Could not find a package configuration file provided by "realsense2" with any of the following names: realsense2Config.cmake realsense2-config.cmake Add the installation prefix of "realsense2" to CMAKE_PREFIX_PATH or set "realsense2_DIR" to a directory containing one of the above files. If "realsense2" provides a separate development package or SDK, be sure it has been installed. CMake Error at CMakeLists.txt:116 (add_subdirectory): add_subdirectory given source "Thirdparty/g2o" which is not an existing directory. -- Configuring incomplete, errors occurred! See also "/home/robot/XTDrone/sensing/slam/vslam/ORB_SLAM3/build/CMakeFiles/CMakeOutput.log". make: *** 没有指明目标并且找不到 makefile。 停止。
最新发布
07-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值