运行如下指令:
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
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/ ..
Could NOT find GTest ## 没有安装GTest
方法一:
查找是否存在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
#set(CMAKE_CXX_FLAGS "-std=c++11 -Wall")
#set(CMAKE_CXX_FLAGS_RELEASE "-std=c++14 -O3 -fopenmp -pthread")
set(CMAKE_CXX_STANDARD 14 )
sudo apt-get install freeglut3-dev
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
)
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
/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)
DEFINE_string(config_file, "../config/default.yaml", "config file path");
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
阿里云盘
将下载好的数据集提取到/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