SLAM十四讲报错解决(1)

问题:第5讲跑stereoVision.cpp出现错误。寻找解决办法的过程中,发现只是CMakeList.txt的问题,版本为ubuntu20.04,最终不报错的CMakeList.txt在文章后半部分给出。

本来已经修改CmakeList.txt为:

cmake_minimum_required( VERSION 2.8 )
project(stereo)
 
set( CMAKE_CXX_FLAGS "-std=c++11")
find_package(Pangolin REQUIRED)

 
add_executable(stereoVision stereoVision.cpp)
# 链接OpenCV库
target_link_libraries(stereoVision ${OpenCV_LIBS} ${Pangolin_LIBRARIES})

在build目录下键入cmake ..出现以下警告:

CMake Deprecation Warning at CMakeLists.txt:7 (cmake_minimum_required):
  Compatibility with CMake < 3.10 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value.  Or, use the <min>...<max> syntax
  to tell CMake that the project requires at least <min> but has been updated
  to work with policies introduced by <max> or earlier.


-- Configuring done (0.0s)
-- Generating done (0.0s)
-- Build files have been written to: /home/rosnoetic/catkin_ws/src/slambook2/ch5/stereo/build

导致make的时候出现了一大串错误,截取部分错误如下:

/usr/local/include/sigslot/signal.hpp:109:79: error: ‘decay_t’ is not a member of ‘std’; did you mean ‘decay’?
  109 | _weak_ptr_compatible_v = detail::is_weak_ptr_compatible<std::decay_t<P>>::value;
      |                                                              ^~~~~~~
      |                                                              decay
/usr/local/include/sigslot/signal.hpp:109:79: error: ‘decay_t’ is not a member of ‘std’; did you mean ‘decay’?
  109 | _weak_ptr_compatible_v = detail::is_weak_ptr_compatible<std::decay_t<P>>::value;
      |                                                              ^~~~~~~
      |                                                              decay
/usr/local/include/sigslot/signal.hpp:109:87: error: template argument 1 is invalid

查看VScode中的问题如下:

现在查找解决方案。 

首先解决cmake ..编译报错,根据cmake的提示 CMakeLists.txt 中 cmake_minimum_required 的版本要求太低了,可能无法兼容,将最小版本要求更新或者添加一个区间即可。

因为要大于3.10,选择cmake版本为3.10,也就是CMakeLists.txt中改为 cmake_minimum_required( VERSION 3.10 )

查看系统的cmake版本:

cmake --version
cmake version 3.31.2

编译不warning了,但是make仍然报错。找了很久,发现是CMakeLists.txt和我的ubuntu20.04版本不同,需要注释掉以下一行:

set( CMAKE_CXX_FLAGS "-std=c++11")

运行后不见原来的报错,但还是有报错。

/usr/bin/ld: CMakeFiles/stereoVision.dir/stereoVision.cpp.o: in function `main':
stereoVision.cpp:(.text+0xae): undefined reference to `cv::imread(cv::String const&, int)'
/usr/bin/ld: stereoVision.cpp:(.text+0xf1): undefined reference to `cv::imread(cv::String const&, int)'
/usr/bin/ld: stereoVision.cpp:(.text+0x136): undefined reference to `cv::StereoSGBM::create(int, int, int, int, int, int, int, int, int, int, int)'
/usr/bin/ld: stereoVision.cpp:(.text+0x251): undefined reference to `cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const'
/usr/bin/ld: stereoVision.cpp:(.text+0x4fa): undefined reference to `cv::operator/(cv::Mat const&, double)'
/usr/bin/ld: stereoVision.cpp:(.text+0x513): undefined reference to `cv::_InputArray::_InputArray(cv::MatExpr const&)'
/usr/bin/ld: stereoVision.cpp:(.text+0x542): undefined reference to `cv::imshow(cv::String const&, cv::_InputArray const&)'
/usr/bin/ld: stereoVision.cpp:(.text+0x579): undefined reference to `cv::waitKey(int)'
/usr/bin/ld: CMakeFiles/stereoVision.dir/stereoVision.cpp.o: in function `cv::String::String(char const*)':
stereoVision.cpp:(.text._ZN2cv6StringC2EPKc[_ZN2cv6StringC5EPKc]+0x58): undefined reference to `cv::String::allocate(unsigned long)'
/usr/bin/ld: CMakeFiles/stereoVision.dir/stereoVision.cpp.o: in function `cv::String::~String()':
stereoVision.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x18): undefined reference to `cv::String::deallocate()'
/usr/bin/ld: CMakeFiles/stereoVision.dir/stereoVision.cpp.o: in function `cv::String::operator=(cv::String const&)':
stereoVision.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x2c): undefined reference to `cv::String::deallocate()'
/usr/bin/ld: CMakeFiles/stereoVision.dir/stereoVision.cpp.o: in function `cv::Mat::~Mat()':
stereoVision.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x3d): undefined reference to `cv::fastFree(void*)'
/usr/bin/ld: CMakeFiles/stereoVision.dir/stereoVision.cpp.o: in function `cv::Mat::release()':
stereoVision.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4f): undefined reference to `cv::Mat::deallocate()'
/usr/bin/ld: CMakeFiles/stereoVision.dir/stereoVision.cpp.o: in function `cv::String::String(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&)':
stereoVision.cpp:(.text._ZN2cv6StringC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN2cv6StringC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x61): undefined reference to `cv::String::allocate(unsigned long)'
collect2: error: ld returned 1 exit status
make[2]: *** [CMakeFiles/stereoVision.dir/build.make:118:stereoVision] 错误 1
make[1]: *** [CMakeFiles/Makefile2:87:CMakeFiles/stereoVision.dir/all] 错误 2
make: *** [Makefile:91:all] 错误 2

再次搜索,把CMakeLists.txt改成如下:

cmake_minimum_required( VERSION 3.10 )
project(stereo)

find_package(Pangolin REQUIRED)
 
find_package(OpenCV REQUIRED)     
include_directories(${OpenCV_INCLUDE_DIRS})  #add by csq
#添加Eigen头文件
include_directories("/usr/include/eigen3")   #add by csq ,根据你的安装路径来选择
# set(CMAKE_CXX_FLAGS "-std=c++11")
 
add_executable(stereoVision stereoVision.cpp)
target_link_libraries(stereoVision ${OpenCV_LIBS} ${Pangolin_LIBRARIES})

cmake ..和make都不报错了

 将要测试的两张图粘贴到build文件夹中,然后继续在build目录下运行:

./stereoVision 

得到视差图:

 

 点云图如下:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值