注意:该文章为公开免费的项目,我做这件事旨在让后来者少走弯路,如果大家对于编译Opencv过程中的错误有很好的解决方式,也可以私信我,我会将大家的回答放到该文档内,并注明作者。本文章一直更新。
1.DetectCXXCompiler.cmake
CMake执行【configure】后,信息栏提示:
CMake Warning at cmake/OpenCVDetectCXXCompiler.cmake:175 (message): OpenCV does not recognize MSVC_VERSION "1923". Cannot set OpenCV_RUNTIME Call Stack (most recent call first): CMakeLists.txt:153 (include)
(注意:配置为Windows 10专业版22H2,VS2022)
这是一个vs2022常见问题,主要是由于MSC_VER 未对应vs版本
解决方法:
在Opencv源文件内找到下面这个文件
按照提示要求,找到第175行代码
将周围的代码改成和我一样的
cpp
if(MSVC_VERSION EQUAL 1400)
set(OpenCV_RUNTIME vc8)
elseif(MSVC_VERSION EQUAL 1500)
set(OpenCV_RUNTIME vc9)
elseif(MSVC_VERSION EQUAL 1600)
set(OpenCV_RUNTIME vc10)
elseif(MSVC_VERSION EQUAL 1700)
set(OpenCV_RUNTIME vc11)
elseif(MSVC_VERSION EQUAL 1800)
set(OpenCV_RUNTIME vc12)
elseif(MSVC_VERSION EQUAL 1900)
set(OpenCV_RUNTIME vc14)
elseif(MSVC_VERSION EQUAL 1910)
set(OpenCV_RUNTIME vc15)
elseif(MSVC_VERSION EQUAL 1923)
set(OpenCV_RUNTIME vc16)
elseif(MSVC_VERSION MATCHES "^193[0-9]$")
set(OpenCV_RUNTIME vc17)
else()
message(WARNING "OpenCV does not recognize MSVC_VERSION \"${MSVC_VERSION}\". Cannot set OpenCV_RUNTIME")
endif()
elseif(MINGW)
set(OpenCV_RUNTIME mingw)
if(CMAKE_SYSTEM_PROCESSOR MATCHES "amd64.*|x86_64.*|AMD64.*")
set(OpenCV_ARCH x64)
else()
set(OpenCV_ARCH x86)
endif()
endif()
,随后在Cmake中重新执行【configure】,就会发现改红色错误消失。
2.CONFIGURATION IS NOT SUPPORTED
CMake Warning at cmake/OpenCVGenSetupVars.cmake:54 (message):CONFIGURATION IS NOT SUPPORTED: validate setupvars script in install directoryCall Stack (most recent call first):CMakeLists.txt:985 (include)
该提示是有关是否给opencv自动配置环境的,为了消除这个红色错误,仅需在cmake内找到【OPENCV_GENERATE_SETUPVARS】,取消勾选即可。
注:OPENCV_GENERATE_SETUPVARS
是一个布尔变量,用于指定是否生成用于设置OpenCV环境变量的文件。当设置为ON
时,CMake会在安装OpenCV时生成一个名为opencv_generated_setupvars.cmake
的文件。这个文件包含了设置环境变量所需的命令,比如将OpenCV的路径添加到PATH
环境变量中,以便在编译和运行时能够正确地找到OpenCV库和头文件。
然后再次进行【configure】即可
3.PYTHON_EXECUTABLE
CMake Warning at cmake/OpenCVDetectPython.cmake:81 (message):
CMake's 'find_host_package(PythonInterp 2.7)' found wrong Python version:
PYTHON_EXECUTABLE=D:/Anaconda/python.exe
PYTHON_VERSION_STRING=3.6.5
Consider providing the 'PYTHON2_EXECUTABLE' variable via CMake command line
or environment variables
Call Stack (most recent call first):
cmake/OpenCVDetectPython.cmake:271 (find_python)
CMakeLists.txt:611 (include)
该提示是说 我们的电脑里没有Python2.7版本。
先下载一个Python Release Python 2.7.0 | Python.org
桌面"计算机"右键选择"属性",在弹出"系统"窗口左侧选择"高级系统设置",弹出"系统属性窗口"。
依次选择"系统属性">>>"高级">>>"环境变量",弹出"环境变量"窗口。
"系统变量"栏选择"新建",按下图操作: