Incomprehensible Compilation Error (OpenCV with CUDA on Windows)

Hello guys,

I’m facing a tough situation for which Google is no help. I hope someone here can enlighten me.

I’m trying to install OpenCV on my Windows PC, with CUDA support. There are a few tutorials on how to do that, and they all pretty much amount to the same thing : no precompiled binary exists, so I need to download the source, configure the makefiles and build opencv using Visual Studio.

Except it fails. At some point, the compiler chokes on a source file named “xutility” (no suffix…) and vomits out a number of what looks like fairly basic syntax errors :


There’s a hundred of those before the compiler gives up, but I’m sure there are many more. This appears to be related to some C++ 11 template black magic that, I’m sorry to say, I know nothing about and have no intention of learning about. The source file makes abundant use of the constexpr keyword and that seems to be the problem.

It’s supposed to be some sort of dynamic macro and it appears the compiler doesn’t know how to expand it, resulting in all those errors.

Given that I didn’t do anything esoteric (just followed a tutorial) I’m very surprised that I appear to be the only guy to who this is happening, so I’m hoping this is something really obvious like forgetting to put fuel in the tank.

I’m joining the aforementioned source file : (35.6 KB)

Note that this not an OpenCV file but belongs to Visual Studio (C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include)

2402 left parenthesis
2473 right parenthesis
I think there are 71 left parenthesis missing from somewhere.

1 Like

I’m still looking into this mess, but nothing is any clearer.

OpenCV contains 196 programs that are built in one go. The error only happens during the compilation of one program : opencv_test_cudev. To make sure, I’ve tried building several other programs separately (by right-clicking them and hitting “build”) and each one I’ve tried has indeed compiled with no error.

I obviously googled opencv_test_cudev and lo and behold, the first result was about compilation errors. Here’s an excerpt :

ovis is the culprit. Build was successful if disable ovis by adding to cmake line


“ovis” is the OGRE 3D visualizer. I have no idea why it would cause a compilation error. I also believe that everything should compile, so I’m not going to start chopping off bits and pieces of OpenCV in an attempt to make the rest work.

Thoughts, anyone ? I’m feeling very much alone on this thing. Everyone with OpenCV compilation problem seems to have their own unique type of issue…

I ran into the same problem. I’m using VS 2019 and I’m trying to compile OpenCV 4.5.5 with CUDA 11 and -DBUILD_TESTS_ON. The opencv_test_cudev project does not build because of the errors that you describe.
If you open the CMakeLists.txt file in the cudev module you will see lines that determine the command line option “-std=c++14” or “-std=c++11”. I changed “-std=c++14” to “-std=c++17” and it builds now. Look for the cudev module in the contrib/modules directory.
The cuda compiler is including files with “if constexpr” and that is a C++17 feature. So I told it to use C++17.


Thanks, man ! This seems like an easy fix.

I’ve put OpenCV on the backburner but may return to it soon. I’ll be sure to use your solution.