slambook2(ch13)—— Ubuntu18.04安装GFlags + GLog + gtest + 例程演示

slambook2(ch13)—— Ubuntu18.04安装GFlags + GLog + gtest + 例程演示

  • 一、安装 GFlags
  • 二、安装 GLog
  • 三、gtest安装
    • 1.报错:
    • 2.报错:找不到 - lglut
    • 3.报错:“fmt”
    • 4.报错:链接失败
    • 5.报错:
    • 6.修改路径:
    • 7.可能遇到的报错
      • 运行时会出现 `ParseCommandLineFlags is not a member of 'google’`的错误
      • 报错:`error: ‘CV_FILLED’ was not declared in this scope feat->position_.pt + cv::Point2f(10, 10), 0, CV_FILLED);`
      • 报错:`VO is running Segmentation fault (core dumped)`
      • 报错:`error: ‘CV_GRAY2BGR’ was not declared in this scope cv::cvtColor(current_frame_->left_img_, img_out, CV_GRAY2BGR);`
  • 四、下载kitti数据
  • 五、运行程序

一、安装 GFlags

运行如下指令:

git clone https://github.com/gflags/gflags.git
cd gflags
mkdir build && cd build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=ON -DGFLAGS_NAMESPACE=gflags ../ 
make -j4
sudo make install

二、安装 GLog

git clone https://ghproxy.com/https://github.com/google/glog
sudo apt-get install autoconf automake libtool
cd glog
mkdir build
cd build
cmake ..
make
sudo make install

初次编译glog时如果出错,如下图所示,网上搜索解决方案,需要把glfag编译成动态库或者使用apt-get方法进行安装。

重新执行gflags的安装过程,将gflag编译成动态链接库

cmake -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC -DBUILD_SHARED_LIBS=ON -DBUILD_STATIC_LIBS=ON -DINSTALL_HEADERS=ON -DINSTALL_SHARED_LIBS=ON -DINSTALL_STATIC_LIBS=ON -DCMAKE_INSTALL_PREFIX=/usr/ ..

三、gtest安装

  Could NOT find GTest ## 没有安装GTest

slambook2(ch13)—— Ubuntu18.04安装GFlags + GLog + gtest + 例程演示_第1张图片

方法一:
查找是否存在gtest文件

cd /usr/src/gtest
sudo cmake CMakeLists.txt
sudo make
sudo cp *.a /usr/lib

方法二:

git clone https://ghproxy.com/https://github.com/google/googletest.git
cd googletest
mkdir build
cd build
cmake ..
make
sudo make install

1.报错:

slambook2(ch13)—— Ubuntu18.04安装GFlags + GLog + gtest + 例程演示_第2张图片
修改CMakeLists.txt :

#set(CMAKE_CXX_FLAGS "-std=c++11 -Wall")
#set(CMAKE_CXX_FLAGS_RELEASE  "-std=c++14 -O3 -fopenmp -pthread")
set(CMAKE_CXX_STANDARD 14 )

2.报错:找不到 - lglut

slambook2(ch13)—— Ubuntu18.04安装GFlags + GLog + gtest + 例程演示_第3张图片
这是因为缺少包,执行如下命令,安装freeglut即可

sudo apt-get install freeglut3-dev

3.报错:“fmt”

slambook2(ch13)—— Ubuntu18.04安装GFlags + GLog + gtest + 例程演示_第4张图片
修改CMakeLists.txt :

set(THIRD_PARTY_LIBS
        ${OpenCV_LIBS}
        ${Sophus_LIBRARIES}
        ${Pangolin_LIBRARIES} GL GLU GLEW glut
        g2o_core g2o_stuff g2o_types_sba g2o_solver_csparse g2o_csparse_extension
        ${GTEST_BOTH_LIBRARIES}
        ${GLOG_LIBRARIES}
        ${GFLAGS_LIBRARIES}
        pthread
        ${CSPARSE_LIBRARY}
        fmt
        )

4.报错:链接失败

slambook2(ch13)—— Ubuntu18.04安装GFlags + GLog + gtest + 例程演示_第5张图片
如果遇到

 relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5’ can not be used when making a shared object; recompile with -fPIC

的错误,这是由于链接库中使用了libfmt.a与libmyslam.so,编译时动态库与静态库不能混用。.a是静态库,.so是动态库,具体问题具体分析,有的是因为gflags安装是安装的静态库,如下图所示,而我的问题是fmt是静态库,需要在编译时(cmake … -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC …)稍加注意,改成动态库就行了。
改成动态库的具体操作步骤、解决办法:
重新编译安装fmt包:

git clone  https://ghproxy.com/https://github.com/fmtlib/fmt.git
cd fmt/
mkdir build
cd build
cmake .. -DGFLAGS_NAMESPACE=google -DCMAKE_CXX_FLAGS=-fPIC ..
make -j8
sudo make install

5.报错:

/usr/local/include/g2o/core/base_fixed_sized_edge.h:174:32: error: ‘index_sequence’ is not a member of ‘std’
   ......

方法:将CMakeLists.txt文件中关于c++11设置注释掉同时设置c++14,如下

# set(CMAKE_CXX_FLAGS "-std=c++11 -Wall")
# set(CMAKE_CXX_FLAGS_RELEASE  "-std=c++11 -O3 -fopenmp -pthread")
set(CMAKE_CXX_STANDARD 14)

6.修改路径:

DEFINE_string(config_file, "../config/default.yaml", "config file path");

7.可能遇到的报错

slambook2(ch13)—— Ubuntu18.04安装GFlags + GLog + gtest + 例程演示_第6张图片

运行时会出现 ParseCommandLineFlags is not a member of 'google’的错误

我们将slambook2/ch13/app下的run_kitti_stereo.cpp中的

google::ParseCommandLineFlags(&argc, &argv, true);

//修改为

gflags::ParseCommandLineFlags(&argc, &argv, true);

run_kitti_stereo.cpp:

int main(int argc, char **argv) {
    google::ParseCommandLineFlags(&argc, &argv, true);
 //   gflags::ParseCommandLineFlags(&argc, &argv, true);

    myslam::VisualOdometry::Ptr vo(
        new myslam::VisualOdometry(FLAGS_config_file));
 //   assert(vo->Init() == true);
    vo->Init();
    vo->Run();

    return 0;
}

再进行编译运行即可。
编译后还不行那就重装GFlags&GLog

报错:error: ‘CV_FILLED’ was not declared in this scope feat->position_.pt + cv::Point2f(10, 10), 0, CV_FILLED);

slambook2/ch13/src/frontend.cpp:295:68: error: ‘CV_FILLED’ was not declared in this scope
                       feat->position_.pt + cv::Point2f(10, 10), 0, CV_FILLED);
将CV_FILLED改为cv::FILLED即可

报错:VO is running Segmentation fault (core dumped)

WARNING: Logging before InitGoogleLogging() is written to STDERR
I20210712 22:42:13.808815 12504 visual_odometry.cpp:44] VO is running
Segmentation fault (core dumped)

打开run_kitti_stereo.cpp注释掉assert函数将初始提取出来,如下

 //   assert(vo->Init() == true);
    vo->Init();
    vo->Run();

报错:error: ‘CV_GRAY2BGR’ was not declared in this scope cv::cvtColor(current_frame_->left_img_, img_out, CV_GRAY2BGR);

/home/kbfvictory/Downloads/slambook2/ch13/src/viewer.cpp:83:54: error: ‘CV_GRAY2BGR’ was not declared in this scope
     cv::cvtColor(current_frame_->left_img_, img_out, CV_GRAY2BGR);

在viewer.cpp h中加入头文件,如下:

#include 

四、下载kitti数据

阿里云盘
将下载好的数据集提取到/slambook2/ch13/Data下,修改/slambook2/ch13/config下载default.yaml中的路径为数据集所在路径,我的数据集放在~/slambook2/ch13/Data/ 对应的default.yaml为

# dataset_dir: /media/xiang/Data/Dataset/Kitti/dataset/sequences/00
#dataset_dir: /mnt/1A9286BD92869CBF/Dataset/Kitti/dataset/sequences/05
dataset_dir: /home/sfann/slam14_code/slambook2/ch13/date/00

五、运行程序

./bin/run_kitti_stereo

你可能感兴趣的:(slambook2,实践复现,linux,slam,ubuntu,计算机视觉,自动驾驶)