1.错误提示:
: && /usr/bin/c++ -fPIC -O3 -DNDEBUG -shared -Wl,-soname,libmyslam.so -o ../lib/libmyslam.so src/CMakeFiles/myslam.dir/frame.cpp.o src/CMakeFiles/myslam.dir/mappoint.cpp.o src/CMakeFiles/myslam.dir/map.cpp.o src/CMakeFiles/myslam.dir/camera.cpp.o src/CMakeFiles/myslam.dir/config.cpp.o src/CMakeFiles/myslam.dir/feature.cpp.o src/CMakeFiles/myslam.dir/frontend.cpp.o src/CMakeFiles/myslam.dir/backend.cpp.o src/CMakeFiles/myslam.dir/viewer.cpp.o src/CMakeFiles/myslam.dir/visual_odometry.cpp.o src/CMakeFiles/myslam.dir/dataset.cpp.o -Wl,-rpath,/usr/local/lib/x86_64-linux-gnu:/usr/local/lib /usr/local/lib/x86_64-linux-gnu/libopencv_dnn.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_ml.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_objdetect.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_shape.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_stitching.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_superres.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_videostab.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_viz.so.3.4.1 /usr/local/lib/libpango_glgeometry.so /usr/local/lib/libpango_plot.so /usr/local/lib/libpango_python.so /usr/local/lib/libpango_scene.so /usr/local/lib/libpango_tools.so /usr/local/lib/libpango_video.so -lGL -lGLU -lGLEW -lglut -lg2o_core -lg2o_stuff -lg2o_types_sba -lg2o_solver_csparse -lg2o_csparse_extension /usr/local/lib/x86_64-linux-gnu/libgtest.a /usr/local/lib/x86_64-linux-gnu/libgtest_main.a /usr/local/lib/x86_64-linux-gnu/libglog.a /usr/local/lib/libgflags.so.2.2.2 -lpthread -lcxsparse -lfmt /usr/local/lib/x86_64-linux-gnu/libopencv_calib3d.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_features2d.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_flann.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_highgui.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_photo.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_video.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_videoio.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_imgcodecs.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_imgproc.so.3.4.1 /usr/local/lib/x86_64-linux-gnu/libopencv_core.so.3.4.1 /usr/local/lib/libpango_geometry.so /usr/local/lib/libtinyobj.so /usr/local/lib/libpango_display.so /usr/local/lib/libpango_vars.so /usr/local/lib/libpango_windowing.so /usr/local/lib/libpango_opengl.so -lGLEW -lOpenGL -lGLX -lGLU /usr/local/lib/libpango_image.so /usr/local/lib/libpango_packetstream.so /usr/local/lib/libpango_core.so -lrt /usr/local/lib/x86_64-linux-gnu/libgtest.a -lpthread && :
/usr/bin/ld: //usr/local/lib/x86_64-linux-gnu/libfmt.a(format.cc.o): relocation R_X86_64_PC32 against symbol `stderr@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: 最后的链结失败: 错误的值
collect2: error: ld returned 1 exit status
ninja: build stopped: subcommand failed.
解决方案:
- 打开fmt下面的CmakeList.txt文件,添加-fPIC参数,如下:
add_compile_options(-fPIC)
- 该参数用于静态库链接成.so动态库,编译静态库的时候需要加 -fPIC这个参数。
- 重新编译
mkdir build
cd build
cmake ..
make
sudo make install
参考:【slam十四讲第二版】【课本例题代码向】【第十三讲~实践:设计SLAM系统】_踏破万里无云的博客-CSDN博客
2.在CMakeList.txt文件中的set(THIRD_PARTY_LIBS)中加入fmt
3.find_package(OpenCV 2 REQUIRED)改为find_package(OpenCV REQUIRED)
4.将CMakeLists.txt中的c++11标准改为c++ 14
#set(CMAKE_CXX_FLAGS "-std=c++14 -Wall")
#set(CMAKE_CXX_FLAGS_RELEASE "-std=c++14 -O3 -fopenmp -pthread")
set(CMAKE_CXX_STANDARD 14)
5.代码中的CV_GRAY2BGR改成COLOR_GRAY2BGR
6.修改app/run_kitti_stereo.cpp
,注释掉assert这句代码,将vo->Init() == true
提取出来。
int main(int argc, char **argv) {
google::ParseCommandLineFlags(&argc, &argv, true); //必要的初始化
myslam::VisualOdometry::Ptr vo(
new myslam::VisualOdometry(FLAGS_config_file)); //使用参数要在参数名前加上FLAG_
//assert(vo->Init() == true);
vo->Init() ;
vo->Run();
return 0;
}
7.代码中的CV_FILLED改为cv::FILLED
8.在ch13/ 的路径下执行 ./bin/run_kitti_stereo
- 如果是在ch13/bin/的路径下执行,要将run_kitti_stereo.cpp文件中的DEFINE_string()进行修改,"./config/default.yaml"改为"../config/default.yaml"
DEFINE_string(config_file, "./config/default.yaml", "config file path");
9.个人在运行代码中发现会出现“段错误”,后来发现是因为config.h中的Get函数造成的,具体原因还未搞清,希望如果有懂的大佬能告诉我,在这里我就将原来visual_odometry.cpp中使用到Get()读取yaml文件元素的部分替换为直接输入参数:
dataset_ =
Dataset::Ptr(new Dataset("/home/kukulin/05"));
Frontend::Frontend() {
gftt_ =
cv::GFTTDetector::create(150, 0.01, 20); //Config::Get<int>("num_features")改了
num_features_init_ = 50;//Config::Get<int>("num_features_init");
num_features_ = 150;//Config::Get<int>("num_features");
}