请选择 进入手机版 | 继续访问电脑版

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

[复制链接]
查看: 566|回复: 0

56

主题

58

帖子

224

积分

版主

Rank: 7Rank: 7Rank: 7

积分
224
发表于 2021-11-30 13:02:07 | 显示全部楼层 |阅读模式
本帖最后由 aijc8 于 2021-11-30 13:07 编辑

[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

搜索该问题,一击必中。

解决方法:

  1. if(DEFINED OpenCV_ARCH AND DEFINED OpenCV_RUNTIME)
  2.   # custom overridden values
  3. elseif(MSVC)
  4.   if(CMAKE_CL_64)
  5.     set(OpenCV_ARCH x64)
  6.   elseif((CMAKE_GENERATOR MATCHES "ARM") OR ("${arch_hint}" STREQUAL "ARM") OR (CMAKE_VS_EFFECTIVE_PLATFORMS MATCHES "ARM|arm"))
  7.     # see Modules/CmakeGenericSystem.cmake
  8.     set(OpenCV_ARCH ARM)
  9.   else()
  10.     set(OpenCV_ARCH x86)
  11.   endif()
  12.   if(MSVC_VERSION EQUAL 1400)
  13.     set(OpenCV_RUNTIME vc8)
  14.   elseif(MSVC_VERSION EQUAL 1500)
  15.     set(OpenCV_RUNTIME vc9)
  16.   elseif(MSVC_VERSION EQUAL 1600)
  17.     set(OpenCV_RUNTIME vc10)
  18.   elseif(MSVC_VERSION EQUAL 1700)
  19.     set(OpenCV_RUNTIME vc11)
  20.   elseif(MSVC_VERSION EQUAL 1800)
  21.     set(OpenCV_RUNTIME vc12)
  22.   elseif(MSVC_VERSION EQUAL 1900)
  23.     set(OpenCV_RUNTIME vc14)
  24.     //插入注释下面两段话,这里的MSVC_VERSION即表中的_MSC_VER,当1923时,是vc16,使其能识别vs2019的VC++,具体_MSC_VER值见附表
  25.   elseif(MSVC_VERSION EQUAL 1910)
  26.     set(OpenCV_RUNTIME vc15)
  27.   elseif(MSVC_VERSION EQUAL 1923)
  28.     set(OpenCV_RUNTIME vc16)
  29.   elseif(MSVC_VERSION MATCHES "^193[0-9][        DISCUZ_CODE_0        ]quot;)
  30.     set(OpenCV_RUNTIME vc17)
  31.   else()
  32.     message(WARNING "OpenCV does not recognize MSVC_VERSION "${MSVC_VERSION}". Cannot set OpenCV_RUNTIME")
  33.   endif()
  34. elseif(MINGW)
  35.   set(OpenCV_RUNTIME mingw)

  36.   if(MINGW64)
  37.     set(OpenCV_ARCH x64)
  38.   else()
  39.     set(OpenCV_ARCH x86)
  40.   endif()
  41. 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


AI教程吧走一走,高薪迟早有!
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

精彩课程推荐
AI教程吧-更新最快的IT教程网 本站资源原自互联网收集及网友分享-如有侵权请发邮件到chenwei@aijc8.com联系删除!  AI教程吧  ( 辽ICP备20003934号-1 )