CMake error when building OpenCV - CMakeLists not match

笑着哭i 提交于 2020-01-12 23:04:38

问题


I tried to build OpenCV 3.1.0 on my Raspberry Pi 2B. Unfortunetly, when I trying:

cmake -D CMAKE_BUILD_TYPE=RELEASE \ -D CMAKE_INSTALL_PREFIX=/usr/local \ -D INSTALL_C_EXAMPLES=OFF \ -D INSTALL_PYTHON_EXAMPLES=OFF /home/pi/Downloads/opencv-3.1.0

It gave me a error :( :

CMake Error: The source "/home/pi/Downloads/opencv-3.1.0/CMakeLists.txt" does not match the source "/home/pi/Downloads/opencv-3.1.0/modules/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.

I want to use OpenCV with C++ and Code::Bocks, which I have already installed. I can't found any solution on internet, so I will be very happy if smb help me. :) Forgot to say I using Raspbian Jezzy.


回答1:


First, I hope you do run CMake outside your sources, in a separate directory. Not doing that is really not recommended

To understand the error message you have to know a little bit on how CMake works.

Basically, when you run

cd /path/to/opencv
mkdir build
cd build
cmake ..

CMake generates a cache in the build dir (It's a simple file named CMakeCache.txt). This file contains some information like:

  • The path to the sources /path/to/opencv
  • The path to the build dir /path/to/opencv/build
  • The CMake Generator used (Ninja, Unix Makefiles ...)

If you ever re-run CMake and change one of these values, (by re-running cmake with different arguments, setting an other generotor or moving files), CMake will complain with this kind of message.

A good solution is then to delete the CMakeCache, or even the whole build dir to be safe.




回答2:


The reason is you have used two version of cmake to generate the Makefile.

cd /path/to/opencv
rm -rf build
mkdir build
cd build
cmake ..

that will be work fine.

  • Installing OpenCV 2.4.9 in Ubuntu 14.04 LTS http://www.samontab.com/web/2014/06/installing-opencv-2-4-9-in-ubuntu-14-04-lts/


来源:https://stackoverflow.com/questions/35784700/cmake-error-when-building-opencv-cmakelists-not-match

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!