windows下cmake编译opencv3.4.1+opencv_contrib报错

编译可以参考https://blog.csdn.net/ezhchai/article/details/80557936

问题一:

 CMake Warning (dev) at cmake/common.cmake:5 (source_group):
    Syntax error in cmake code at

      C:/yumen/wxgisgdal-read-only/cmake/common.cmake:5

    when parsing string

      Header Files\\ogr\ogrsf_frmts

    Invalid escape sequence \o

出现的错误代码段:

#add data
 macro(add_files_macro FPATH FGROUP)
     file(GLOB GDAL_AHHEADERS ${FPATH}/*.h  ${FPATH}/*.hpp)
     set(GDAL_HHEADERS ${GDAL_HHEADERS} ${GDAL_AHHEADERS})
     source_group("Header Files\\${FGROUP}" FILES ${GDAL_AHHEADERS})
     file(GLOB GDAL_ACSOURCES ${FPATH}/*.cpp ${FPATH}/*.cc ${FPATH}/*.c)
     set(GDAL_CSOURCES ${GDAL_CSOURCES} ${GDAL_ACSOURCES})
     source_group("Source Files\\${FGROUP}" FILES ${GDAL_ACSOURCES})
 endmacro()

原因:发生错误是因为变量${}的内容包含带有窗口样式分隔符路径,cmake将这些字符视为转移字符

解决:将宏改为一个函数,以避免这种情况。

改为:

#add data 
function(add_files_macro FPATH FGROUP) 
         file(GLOB GDAL_AHHEADERS ${FPATH}/*.h ${FPATH}/*.hpp) 
         set(GDAL_HHEADERS ${GDAL_HHEADERS} ${GDAL_AHHEADERS}) 
         source_group("Header Files\\${FGROUP}" FILES ${GDAL_AHHEADERS}) 
         file(GLOB GDAL_ACSOURCES ${FPATH}/*.cpp ${FPATH}/*.cc ${FPATH}/*.c) 
         set(GDAL_CSOURCES ${GDAL_CSOURCES} ${GDAL_ACSOURCES}) 
         source_group("Source Files\\${FGROUP}" FILES ${GDAL_ACSOURCES}) 
endfunction() 

就是把macro------endmarco 改为了function-----endfunction

问题二:

CMake Error at E:/opencv/opencv3.4.1/opencv/sources/cmake/OpenCVDownload.camke:255(nessage):
  tinny-dnn: Unpack failed:1
Call Stack (most recent call first):
E:/p-opencv-contrib/opencv_contrib-3.4.1/opencv_contrib-3.4.1/moudules/dnn_modern/CMakeLists.txt:18(ocv_download)

所在行txt:18,就是下面第一行

ocv_download(FILENAME "v1.0.0a3.tar.gz"
               HASH "adb1c512e09ca2c7a6faef36f9c53e59"
               URL
                 "${OPENCV_TINY_DNN_URL}"
                 "$ENV{OPENCV_TINY_DNN_URL}"
                 "https://github.com/tiny-dnn/tiny-dnn/archive/"
               DESTINATION_DIR "${TINY_DNN_CPP_PATH}"
               STATUS TINY_DNN_DOWNLOAD_SUCCESS
               ID "tiny-dnn"
               UNPACK RELATIVE_URL)

解决:

需要把

E:/p-opencv-contrib/opencv_contrib-3.4.1/opencv_contrib/3.4.1/moudules/dnn_modern/CMakeLists.txt

中的FILENAM改为PACKAGE

同理,其他类似的地方,都这样替换就行。

你可能感兴趣的:(安装软件出现问题)