构建 OpenCV 时出现 CMake 错误 - CMakeLists 不匹配

CMake error when building OpenCV - CMakeLists not match(构建 OpenCV 时出现 CMake 错误 - CMakeLists 不匹配)

本文介绍了构建 OpenCV 时出现 CMake 错误 - CMakeLists 不匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试在我的 Raspberry Pi 2B 上构建 OpenCV 3.1.0.不幸的是,当我尝试时:

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

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 错误:源/home/pi/Downloads/opencv-3.1.0/CMakeLists.txt"与源/home/pi/Downloads/opencv-3.1.0/modules/CMakeLists.txt"不匹配" 用于生成缓存.使用不同的源目录重新运行 cmake.

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.

我想将 OpenCV 与我已经安装的 C++ 和 Code::Bocks 一起使用.我在互联网上找不到任何解决方案,所以如果 smb 帮助我,我会很高兴.:) 忘了说我用的是 Raspbian Jezzy.

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.

推荐答案

首先,我希望您在单独的目录中外部源代码中运行 CMake.不建议这样做

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.

基本上,当你跑步时

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

CMake 在构建目录中生成缓存(这是一个名为 CMakeCache.txt 的简单文件).该文件包含一些信息,例如:

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

  • 源路径/path/to/opencv
  • 构建目录的路径/path/to/opencv/build
  • 使用的 CMake 生成器(Ninja、Unix Makefiles ...)

如果您重新运行 CMake 并更改这些值之一(通过使用不同参数重新运行 cmake、设置其他生成器或移动文件),CMake 会抱怨此类消息.

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.

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

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

这篇关于构建 OpenCV 时出现 CMake 错误 - CMakeLists 不匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:构建 OpenCV 时出现 CMake 错误 - CMakeLists 不匹配

基础教程推荐