14

I attempted to build OpenCV 3.1.0 on my Raspberry Pi 2B. Unfortunately, when I ran:

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

I received a following 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 find any solution on internet, so I'd be very gratefull if someone helps me. I am using Raspbian Jezzy.

3Qax
  • 324
  • 1
  • 2
  • 12

2 Answers2

30

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.

Dimitri Merejkowsky
  • 1,001
  • 10
  • 12
  • 2
    As you say, the solition was to delete build folder. Thanks for help :) – 3Qax Mar 04 '16 at 08:55
  • 2
    I am using the CMake gui in windows. In addition to deleting the build directory I also (or only?) needed to activate "File > Delete Cache" in the GUI. – gebbissimo Jul 20 '18 at 13:28
  • I ran into this when a CMakeCache.txt file was somehow placed right at the roof of my c: directory. – C.J. Dec 12 '18 at 20:19
4

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.

張正軒
  • 109
  • 1
  • 3