[size=1pc]在尝试用cmake编译opencv3.4.2版本的时候,报错如下,
CMake Warning at cmake/OpenCVDetectCXXCompiler.cmake:147 (message): OpenCV does not recognize MSVC_VERSION "1923". Cannot set OpenCV_RUNTIME Call Stack (most recent call first): CMakeLists.txt:153 (include)
错误排查流程:
排查出报错的位置。在 opencv-3.4.2\cmake\OpenCVDetectCXXCompiler.cmake 文件的147行。
尝试描述该问题,即弄清楚问题是什么——“OpenCV does not recognize MSVC_VERSION “1923”. Cannot set OpenCV_RUNTIME Call Stack (most recent call first)”我的理解是对应的_MSC_VER 1923找不到对应的vc不能设置OpenCV_RUNTIME
搜索该问题,一击必中。
解决方法:
if(DEFINED OpenCV_ARCH AND DEFINED OpenCV_RUNTIME)
# custom overridden values
elseif(MSVC)
if(CMAKE_CL_64)
set(OpenCV_ARCH x64)
elseif((CMAKE_GENERATOR MATCHES "ARM") OR ("${arch_hint}" STREQUAL "ARM") OR (CMAKE_VS_EFFECTIVE_PLATFORMS MATCHES "ARM|arm"))
# see Modules/CmakeGenericSystem.cmake
set(OpenCV_ARCH ARM)
else()
set(OpenCV_ARCH x86)
endif()
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)
//插入注释下面两段话,这里的MSVC_VERSION即表中的_MSC_VER,当1923时,是vc16,使其能识别vs2019的VC++,具体_MSC_VER值见附表
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][ DISCUZ_CODE_0 ]quot;)
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(MINGW64)
set(OpenCV_ARCH x64)
else()
set(OpenCV_ARCH x86)
endif()
endif()
附_MSC_VER值对应的Visual Studio版本
-
Visual Studio version_MSC_VER
Visual Studio 6.0 1200 Visual Studio .NET 2002 (7.0) 1300 Visual Studio .NET 2003 (7.1) 1310 Visual Studio 2005 (8.0) 1400 Visual Studio 2008 (9.0) 1500 Visual Studio 2010 (10.0) 1600 Visual Studio 2012 (11.0) 1700 Visual Studio 2013 (12.0) 1800 Visual Studio 2015 (14.0) 1900 Visual Studio 2017 RTW (15.0) 1910 Visual Studio 2017 version 15.3 1911 Visual Studio 2017 version 15.5 1912 Visual Studio 2017 version 15.6 1913 Visual Studio 2017 version 15.7 1914 Visual Studio 2017 version 15.8 1915 Visual Studio 2017 version 15.9 1916 Visual Studio 2019 RTW (16.0) 1920 Visual Studio 2019 version 16.1 1921 Visual Studio 2019 version 16.2 1922 Visual Studio 2019 version 16.3 1923 Visual Studio 2019 version 16.4 1924 Visual Studio 2019 version 16.5 1925 Visual Studio 2019 version 16.6 1926 VC版本与VS版本对应关系
VSVCVisual Studio 6 : vc6 Visual Studio 2003 : vc7 Visual Studio 2005 : vc8 Visual Studio 2008 : vc9 Visual Studio 2010 : vc10 Visual Studio 2012 : vc11 Visual Studio 2013 : vc12 Visual Studio 2015 : vc14 Visual Studio 2017 : vc15 Visual Studio 2019 : vc16