[C/C++/C#] set 2cmake RUNTIME OpenCV Visual Studio MSVC opencv3.4 报错

[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.01200
    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.31911
    Visual Studio 2017 version 15.51912
    Visual Studio 2017 version 15.61913
    Visual Studio 2017 version 15.71914
    Visual Studio 2017 version 15.81915
    Visual Studio 2017 version 15.91916
    Visual Studio 2019 RTW (16.0)1920
    Visual Studio 2019 version 16.11921
    Visual Studio 2019 version 16.21922
    Visual Studio 2019 version 16.31923
    Visual Studio 2019 version 16.41924
    Visual Studio 2019 version 16.51925
    Visual Studio 2019 version 16.61926

    VC版本与VS版本对应关系

     
    VS
    VC
    Visual 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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值