Bootstrap

视觉SLAM十四讲 报错 Could not find a configuration file for package “OpenCV“ that is compatible with reques

视觉SLAM十四讲 报错 Could not find a configuration file for package "OpenCV" that is compatible with requested version "4".

1. 问题

在编译高博的视觉SLAM十四讲ch8的optical_flow.cpp时,编译报错:

CMake Error at CMakeLists.txt:8 (find_package):
  Could not find a configuration file for package "OpenCV" that is compatible
  with requested version "4".

  The following configuration files were considered but not accepted:

    /usr/local/share/OpenCV/OpenCVConfig.cmake, version: 3.4.16

-- Configuring incomplete, errors occurred!

2. 原因

在第八讲的这个程序里,CMakeLists.txt中编译find_package查找的是OpenCV4,而十四讲前面使用的opencv包括自己编译的都是opencv3版本,所以编译过程找不到相应的库文件以及链接,报错。

3. 解决方案

3.1 修改CMakeLists.txt

简单粗暴,虽然opencv版本不同,但是3到4大部分接口函数都是一样的,所以在CMakeLists.txt中将查找OpenCV4改为查找OpenCV3:

# find_package(OpenCV 4 REQUIRED)
find_package(OpenCV 3 REQUIRED)

然后就可以编译成功了。由于安装的Sophus版本或者G2o版本过高,还可能会出现fmt::v8的链接问题,解决方案在这里

3.2 编译OpenCV4版本

编译OpenCV以及多版本共存问题

;