Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake error when building OpenCV - CMakeLists not match

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.

like image 537
3Qax Avatar asked Mar 03 '16 22:03

3Qax


People also ask

What is CMake and CMakeLists?

CMake is a meta build system that uses scripts called CMakeLists to generate build files for a specific environment (for example, makefiles on Unix machines). When you create a new CMake project in CLion, a CMakeLists. txt file is automatically generated under the project root.

How do I run CMakeLists?

Run cmake-gui.exe, which should be in your Start menu under Program Files, there may also be a shortcut on your desktop, or if you built from source, it will be in the build directory. A GUI will appear similar to what is shown below. The top two entries are the source code and binary directories.

What is the CMakeLists txt file?

CMakeLists. txt file contains a set of directives and instructions describing the project's source files and targets (executable, library, or both). When you create a new project, CLion generates CMakeLists. txt file automatically and places it in the project root directory.


1 Answers

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.

like image 183
Dimitri Merejkowsky Avatar answered Sep 21 '22 15:09

Dimitri Merejkowsky