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 :

image

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 :

xutility.zip (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.

2 Likes

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

-DBUILD_opencv_ovis=OFF

“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.

3 Likes

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.

Hey! I have changed the c++14 to c++17 as you asked to but it still gives the exact same error when I rebuild “ALL_BUILD” in VS 2019.

Here’s my updated CMakeLists.txt in opencv_contrib4.5.2\modules\cudev\test

set(test_deps opencv_cudev opencv_core opencv_imgproc opencv_imgcodecs opencv_videoio opencv_highgui opencv_ts ${OPENCV_MODULE_opencv_ts_DEPS})

ocv_check_dependencies(${test_deps})

if(OCV_DEPENDENCIES_FOUND)
  set(the_target "opencv_test_${name}")

  ocv_module_include_directories("${test_deps}" "${the_module}")

  file(GLOB test_srcs "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" "${CMAKE_CURRENT_SOURCE_DIR}/*.cu")
  file(GLOB test_hdrs "${CMAKE_CURRENT_SOURCE_DIR}/*.hpp")
  source_group("Src" FILES ${test_srcs})
  source_group("Include" FILES ${test_hdrs})
  set(OPENCV_TEST_${the_module}_SOURCES ${test_srcs} ${test_hdrs})

  ocv_cuda_filter_options()

  if(CUDA_VERSION VERSION_LESS "11.0")
    ocv_update(OPENCV_CUDA_OPTIONS_opencv_test_cudev "-std=c++11")
  else()
    ocv_update(OPENCV_CUDA_OPTIONS_opencv_test_cudev "-std=c++17")
    ocv_warnings_disable(CMAKE_CXX_FLAGS -Wdeprecated-declarations)
  endif()

  CUDA_ADD_EXECUTABLE(${the_target} ${OPENCV_TEST_${the_module}_SOURCES} OPTIONS ${OPENCV_CUDA_OPTIONS_opencv_test_cudev})
  ocv_target_link_libraries(${the_target} PRIVATE
      ${test_deps} ${OPENCV_LINKER_LIBS} ${CUDA_LIBRARIES}
  )
  add_dependencies(opencv_tests ${the_target})

  set_target_properties(${the_target} PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL}")
  set_source_files_properties(${OPENCV_TEST_${the_module}_SOURCES} ${${the_target}_pch}
    PROPERTIES LABELS "${OPENCV_MODULE_${the_module}_LABEL};AccuracyTest")

  # Additional target properties
  set_target_properties(${the_target} PROPERTIES
    DEBUG_POSTFIX "${OPENCV_DEBUG_POSTFIX}"
    RUNTIME_OUTPUT_DIRECTORY "${EXECUTABLE_OUTPUT_PATH}"
  )

  if(ENABLE_SOLUTION_FOLDERS)
    set_target_properties(${the_target} PROPERTIES FOLDER "tests accuracy")
  endif()

  ocv_add_test_from_target("${the_target}" "Accuracy" "${the_target}")

  if(INSTALL_TESTS)
    install(TARGETS ${the_target} RUNTIME DESTINATION ${OPENCV_TEST_INSTALL_PATH} COMPONENT tests)
  endif()
endif()

Can you help me out with this? Stuck in the same problem