当构建OpenCV - cmakelist不匹配时发生CMake错误

时间:2022-09-27 04:50:00

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

我尝试在我的覆盆子Pi 2B上构建OpenCV 3.1.0。Unfortunetly,当我尝试:

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

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.

CMake错误:源“/home/pi/Downloads/opencv-3.1.0/CMakeLists。txt“不匹配源”/home/pi/Downloads/opencv-3.1.0/modules/CMakeLists。txt"用于生成缓存。使用不同的源目录重新运行cmake。

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.

我想使用OpenCV与c++和代码::Bocks,我已经安装了。我在网上找不到任何解决方案,所以如果smb能帮助我我会很开心。)忘了说我用的是覆盆子。

2 个解决方案

#1


6  

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

首先,我希望您在源代码之外的另一个目录中运行CMake。不这样做是不推荐的

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

要理解错误消息,您必须了解一些CMake的工作原理。

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:

CMake在构建目录中生成一个缓存(它是一个名为CMakeCache.txt的简单文件)。此文件包含以下信息:

  • The path to the sources /path/to/opencv
  • 到源/路径/到/opencv的路径
  • The path to the build dir /path/to/opencv/build
  • 构建目录/路径/到/opencv/构建的路径
  • The CMake Generator used (Ninja, Unix Makefiles ...)
  • 使用CMake生成器(Ninja, Unix makefile…)

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.

如果您重新运行CMake并更改其中的一个值(通过使用不同的参数重新运行CMake、设置另一个generotor或移动文件),CMake将会对此类消息提出抱怨。

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

然后,一个好的解决方案是删除CMakeCache,甚至整个构建目录以确保安全。

#2


2  

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

原因是您使用了两个版本的cmake来生成Makefile。

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

that will be work fine.

那没问题。

#1


6  

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

首先,我希望您在源代码之外的另一个目录中运行CMake。不这样做是不推荐的

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

要理解错误消息,您必须了解一些CMake的工作原理。

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:

CMake在构建目录中生成一个缓存(它是一个名为CMakeCache.txt的简单文件)。此文件包含以下信息:

  • The path to the sources /path/to/opencv
  • 到源/路径/到/opencv的路径
  • The path to the build dir /path/to/opencv/build
  • 构建目录/路径/到/opencv/构建的路径
  • The CMake Generator used (Ninja, Unix Makefiles ...)
  • 使用CMake生成器(Ninja, Unix makefile…)

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.

如果您重新运行CMake并更改其中的一个值(通过使用不同的参数重新运行CMake、设置另一个generotor或移动文件),CMake将会对此类消息提出抱怨。

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

然后,一个好的解决方案是删除CMakeCache,甚至整个构建目录以确保安全。

#2


2  

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

原因是您使用了两个版本的cmake来生成Makefile。

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

that will be work fine.

那没问题。