使用 OpenCV3.4.5 在 Qt5 中与 Cuda 相关的编译错误

Posted

技术标签:

【中文标题】使用 OpenCV3.4.5 在 Qt5 中与 Cuda 相关的编译错误【英文标题】:Cuda-related compling errors in Qt5 with OpenCV3.4.5 【发布时间】:2019-01-10 14:31:47 【问题描述】:

我使用 VS2015 和 Cuda8.0 构建 OpenCV3.4.5,启用了 Cuda 支持(请参阅这篇文章 How to Build OpenCV for Windows with CUDA)。整个构建过程顺利进行,构建:605 成功,1 失败,0 最新,0 跳过。供您参考,OpenCV3.4.5 的构建配置如下:

-- General configuration for OpenCV 3.4.5 =====================================
  --   Version control:               unknown
  --
  --   Platform:
  --     Timestamp:                   2019-01-09T23:07:28Z
  --     Host:                        Windows 10.0.17134 AMD64
  --     CMake:                       3.9.1
  --     CMake generator:             Visual Studio 14 2015 Win64
  --     CMake build tool:            C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe
  --     MSVC:                        1900
  --
  --   CPU/HW features:
  --     Baseline:                    SSE SSE2 SSE3
  --       requested:                 SSE3
  --     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2
  --       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
  --       SSE4_1 (6 files):          + SSSE3 SSE4_1
  --       SSE4_2 (2 files):          + SSSE3 SSE4_1 POPCNT SSE4_2
  --       FP16 (1 files):            + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 AVX
  --       AVX (6 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
  --       AVX2 (12 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
  --
  --   C/C++:
  --     Built as dynamic libs?:      YES
  --     C++11:                       YES
  --     C++ Compiler:                C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe  (ver 19.0.24215.1)
  --     C++ flags (Release):         /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi      /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP4   /MD /O2 /Ob2 /DNDEBUG
  --     C++ flags (Debug):           /DWIN32 /D_WINDOWS /W4 /GR  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi      /EHa /wd4127 /wd4251 /wd4324 /wd4275 /wd4512 /wd4589 /MP4   /MDd /Zi /Ob0 /Od /RTC1
  --     C Compiler:                  C:/Program Files (x86)/Microsoft Visual Studio 14.0/VC/bin/x86_amd64/cl.exe
  --     C flags (Release):           /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi        /MP4    /MD /O2 /Ob2 /DNDEBUG
  --     C flags (Debug):             /DWIN32 /D_WINDOWS /W3  /D _CRT_SECURE_NO_DEPRECATE /D _CRT_NONSTDC_NO_DEPRECATE /D _SCL_SECURE_NO_WARNINGS /Gy /bigobj /Oi        /MP4  /MDd /Zi /Ob0 /Od /RTC1
  --     Linker flags (Release):      /machine:x64  /INCREMENTAL:NO
  --     Linker flags (Debug):        /machine:x64  /debug /INCREMENTAL
  --     ccache:                      NO
  --     Precompiled headers:         NO
  --     Extra dependencies:          cudart.lib nppc.lib nppial.lib nppicc.lib nppicom.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v8.0/lib/x64
  --     3rdparty dependencies:
  --
  --   OpenCV modules:
  --     To be built:                 calib3d core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev dnn features2d flann highgui imgcodecs imgproc java_bindings_generator ml objdetect photo python3 python_bindings_generator shape stitching superres ts video videoio videostab world
  --     Disabled:                    -
  --     Disabled by dependency:      -
  --     Unavailable:                 java js python2 python2 viz
  --     Applications:                tests perf_tests examples apps
  --     Documentation:               NO
  --     Non-free algorithms:         NO
  --
  --   Windows RT support:            NO
  --
  --   GUI:
  --     QT:                          YES (ver 5.7.0)
  --       QT OpenGL support:         NO
  --     Win32 UI:                    YES
  --     VTK support:                 NO
  --
  --   Media I/O:
  --     ZLib:                        build (ver 1.2.11)
  --     JPEG:                        build-libjpeg-turbo (ver 1.5.3-62)
  --     WEBP:                        build (ver encoder: 0x020e)
  --     PNG:                         build (ver 1.6.35)
  --     TIFF:                        build (ver 42 - 4.0.9)
  --     JPEG 2000:                   build (ver 1.900.1)
  --     OpenEXR:                     build (ver 1.7.1)
  --     HDR:                         YES
  --     SUNRASTER:                   YES
  --     PXM:                         YES
  --
  --   Video I/O:
  --     DC1394:                      NO
  --     FFMPEG:                      YES (prebuilt binaries)
  --       avcodec:                   YES (ver 57.107.100)
  --       avformat:                  YES (ver 57.83.100)
  --       avutil:                    YES (ver 55.78.100)
  --       swscale:                   YES (ver 4.8.100)
  --       avresample:                YES (ver 3.7.0)
  --     GStreamer:                   NO
  --     DirectShow:                  YES
  --     Media Foundation:            YES
  --       DXVA:                      YES
  --
  --   Parallel framework:            Concurrency
  --
  --   Trace:                         YES (with Intel ITT)
  --
  --   Other third-party libraries:
  --     Intel IPP:                   2019.0.0 Gold [2019.0.0]
  --            at:                   E:/In-Field-Sorting-Pro/OpenCV/opencv-3.4.5/cmake-build/3rdparty/ippicv/ippicv_win/icv
  --     Intel IPP IW:                sources (2019.0.0)
  --               at:                E:/In-Field-Sorting-Pro/OpenCV/opencv-3.4.5/cmake-build/3rdparty/ippicv/ippicv_win/iw
  --     Lapack:                      NO
  --     Eigen:                       NO
  --     Custom HAL:                  NO
  --     Protobuf:                    build (3.5.1)
  --
  --   NVIDIA CUDA:                   YES (ver 8.0, CUFFT CUBLAS NVCUVID FAST_MATH)
  --     NVIDIA GPU arch:             20 30 35 37 50 52 60 61
  --     NVIDIA PTX archs:
  --
  --   OpenCL:                        YES (no extra features)
  --     Include path:                E:/In-Field-Sorting-Pro/OpenCV/opencv-3.4.5/sources/3rdparty/include/opencl/1.2
  --     Link libraries:              Dynamic load
  --
  --   Python 3:
  --     Interpreter:                 C:/Python35/python3.exe (ver 3.5.4)
  --     Libraries:                   C:/Python35/libs/python35.lib (ver 3.5.4)
  --     numpy:                       C:/Python35/lib/site-packages/numpy/core/include (ver 1.13.1)
  --     install path:                C:/Python35/Lib/site-packages/cv2/python-3.5
  --
  --   Python (for build):            C:/Python35/python3.exe
  --
  --   Java:
  --     ant:                         NO
  --     JNI:                         NO
  --     Java wrappers:               NO
  --     Java tests:                  NO
  --
  --   Install to:                    C:/opencv-3.4.5/mybuild

使用 Qt5.7 和自建 OpenCV3.4.5,编译我的 Qt 项目会导致数百个与 cuda 相关的错误,其中一部分(例如,`C2061: syntax error: identifier)如下所示:

c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): warning C4002: too many actual parameters for macro 'min'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): error C2182: 'InputArray': illegal use of type 'void'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): error C2146: syntax error: missing ';' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): error C2059: syntax error: ')'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): error C2143: syntax error: missing ';' before '<'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): error C2146: syntax error: missing ')' before identifier 'src2'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): error C2086: 'int cv::cuda::InputArray': redefinition
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): note: see declaration of 'cv::cuda::InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): error C2146: syntax error: missing ';' before identifier 'src2'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): warning C4002: too many actual parameters for macro 'max'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): error C2182: 'InputArray': illegal use of type 'void'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): error C2086: 'int cv::cuda::InputArray': redefinition
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): note: see declaration of 'cv::cuda::InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): error C2146: syntax error: missing ';' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): error C2059: syntax error: ')'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): error C2086: 'int cv::cuda::src1': redefinition
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(296): note: see declaration of 'cv::cuda::src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): error C2059: syntax error: '>'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): error C2146: syntax error: missing ')' before identifier 'src2'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(307): error C2146: syntax error: missing ';' before identifier 'src2'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(330): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(334): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(335): error C2143: syntax error: missing ';' before ''
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(335): error C2447: '': missing function header (old-style formal list?)
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(351): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(361): error C2146: syntax error: missing ')' before identifier 'xy'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(369): error C2146: syntax error: missing ')' before identifier 'xy'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(379): error C2146: syntax error: missing ')' before identifier 'x'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(389): error C2146: syntax error: missing ')' before identifier 'x'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(401): error C2146: syntax error: missing ')' before identifier 'x'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(414): error C2146: syntax error: missing ')' before identifier 'x'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(425): error C2146: syntax error: missing ')' before identifier 'magnitude'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(453): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(455): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(465): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(480): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(494): error C2061: syntax error: identifier 'InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(501): error C2146: syntax error: missing ')' before identifier 'lut'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(518): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(534): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(536): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(546): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(548): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(557): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(559): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(566): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(568): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(575): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(577): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(590): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(592): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(607): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(610): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(621): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(623): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(651): error C2146: syntax error: missing ')' before identifier 'mtx'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(661): error C2146: syntax error: missing ')' before identifier 'mtx'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(663): error C2146: syntax error: missing ')' before identifier 'mtx'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(673): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(691): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(703): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(712): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(744): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(761): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(778): error C2146: syntax error: missing ')' before identifier 'src1'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(815): error C2146: syntax error: missing ')' before identifier 'src'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(828): error C2061: syntax error: identifier 'InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudaarithm.hpp(861): error C2061: syntax error: identifier 'InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudabgsegm.hpp(85): error C2061: syntax error: identifier 'InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudabgsegm.hpp(132): error C2061: syntax error: identifier 'InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudafilters.hpp(84): error C2061: syntax error: identifier 'InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudafilters.hpp(120): error C2061: syntax error: identifier 'InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudafilters.hpp(159): error C2061: syntax error: identifier 'InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudafilters.hpp(261): error C2061: syntax error: identifier 'InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudafeatures2d.hpp(154): error C2061: syntax error: identifier 'InputArray'
c:\opencv-3.4.5\mybuild\include\opencv2/cudafeatures2d.hpp(160): error C2061: syntax error: identifier 'InputArray'

请注意,我的项目可以在没有 Cuda 支持的情况下使用官方预构建的 OpenCV3.4.5 正常工作!所以这些错误一定是因为启用了 cuda 的 opencv 构建。

让我感到困惑的是,我的项目没有明确涉及 cuda 计算,而且我也没有包含任何与 cuda 相关的标头(我的 OpenCV 构建生成单个 opencv_world345 文件)。这些错误的一种可能猜测是不适当的包含标头,例如#include &lt;windows.h&gt;

有没有人遇到过类似的错误?如果我想保留 cuda 功能,而不是使用预构建版本,如何解决它们?

【问题讨论】:

您发布的编译器输出中没有“CUDA 相关”错误。我已删除标签 我只是简单地将那些发生在 opencv2 cuda 相关头文件的错误(例如 C2146)视为“CUDA 相关”错误。我不确定这些错误的确切原因。 【参考方案1】:

我遇到过类似的问题,我可以找到解决方法。 就我而言,我正在同一个项目中构建一个“.dll”,有时是一个“.exe”,用于带有 VS2015 的 Windows。出现错误时,我正在将项目构建为 exe。然后我只是将我的项目切换为构建为 DLL,并且以这种方式构建我得到了更有意义的错误! 在 VS2015 中构建 DLL:

Project->Properties(ALT+F7)->Configuration Properties(列在 左)->常规->常规->目标扩展:.dll“->常规-> ProjectDefaults -> 配置类型:动态库 (.dll) "-> 配置属性(上的列 left)->Linker->System->SubSystem : Windows (/SUBSYSTEM:WINDOWS)

您可能需要将 C++ 对象设置为“DLL 可导出”;这样做:

 //define it when you build as DLL
// undefine it when you build as an exe and undo the steps above in the Project Properties
#define DLL

#ifdef DLL
#define DLL_EXPORT __declspec(dllexport)    //shortens __declspec(dllexport) to DLL_EXPORT
#else
#define DLL_EXPORT 
#endif 


#ifdef __cplusplus  //if C++ is used convert it to C to prevent C++'s name mangling of method names
extern "C"

#endif

class DLL_EXPORT MaGamesClass

public:
  /* your class, as usual */
    MaGamesClass();
    ~MaGamesClass();

    float _soon = 2019;
;

#ifdef __cplusplus

#endif

就我而言,我的 DLL 导出类之一在其构造函数中有一些参数;我发现 DLL 导出的类不喜欢那样......

因此,我只是添加了一些函数来充当构造函数,以满足我的所有需求: MaGames.h:

public : 
        MaGamesClass();
    //Because parameters cannot be set to constructor in DLL (->build error)
    static MaGamesClass MaGamesClass_instantiate(std::string where);
    static MaGamesClass* MaGamesClass_new(std::string where);
        /*
             Return this
        */
    MaGamesClass* init(std::string where);
    ~MaGamesClass();

/*
Some guys prefer initialisation of members in the constructor (MaGamesClass MaGamesClass(): _soon(2019) ... 
I prefered here to avoid as much as possible constructor's build errors
And i find it's more readable anyway :p
*/
      float _soon = 2019; //
      std::string _where;

MaGames.cpp:

using namespace std;

MaGames MaGames::MaGames_instantiate(string where)

    MaGames vrSport= MaGames();
    return *vrSport.init(where);


MaGames MaGames::MaGames_new(string where)
    MaGames* vrSport= new MaGames();
    return vrSport->init(where);


MaGames * MaGames ::init(string where)

    _where = where;
        return this;

使用示例:

MaGames myCenter = MaGamesClass::MaGamesClass_instantiate("France");
MaGames* myCenter = MaGamesClass::MaGamesClass_new("Closer?");

瞧瞧瞧,希望这对大家有帮助

梦想,前进,快乐

【讨论】:

PS:这并没有解决我构建为 exe 应用程序的问题;这只是一种解决方法,知道它作为 DLL 而不是作为 exe 工作可以提供有关分辨率的一些线索【参考方案2】:

对于遇到此问题的任何人,我的解决方案是在 opencv.hpp 之前包含 cudaarithm.hpp任何其他包含的标题,其中包含 opencv.hpp。这在@jingweimo 的接受答案中并不完全清楚

【讨论】:

【参考方案3】:
too many actual parameters for macro 'max'

可能在名为 min 的函数和在您包含的某个文件中定义的宏之间存在冲突定义,可能定义在 windows api 标头中。

您可以尝试在项目的预处理器部分中使用 NOMINMAX 来编译您的项目。

【讨论】:

我正在使用 QtCreator 4.5 来编译项目。添加#define NOMINMAX 并不能解决这些错误。 好的,你能放一个 MCVE,包含描述问题的 .cpp 和 .pro 文件,这样人们就可以尝试在家里重现你的行为。此外,您定义的位置很重要。为确保此定义位于项目的顶部,请不要在代码中自行定义,而是使用 DEFINES += "NOMINMAX" 将其添加到 .pro 文件中的预处理器定义中【参考方案4】:
#include <opencv2/cudaarithm.hpp>

//or 
#include <opencv2/opencv.hpp>

【讨论】:

以上是关于使用 OpenCV3.4.5 在 Qt5 中与 Cuda 相关的编译错误的主要内容,如果未能解决你的问题,请参考以下文章

QT5中QtMultimedia怎么用

如何在 C 中与 Linux 一起使用共享内存

如何在 C/C++ 中与智能卡交互? [关闭]

QWidgets 在 show() 之后不显示——c++/Qt5

Qt5 msvc 2010不识别自动(c ++ 11)[重复]

CMD START不能在Windows 8中与处理器关联使用