Can someone help me with building OpenCV?

Can someone help me with building OpenCV 4.5.5 on Ubuntu 18.04 with CUDA support?

I’m building OpenCV 4.5.5 with CUDA support on my Jetson Nano. But I always encounter the same issue when “make”(I also tried “sudo make”, and had the same issue) is building “modules/cudaarithm”:

[ 85%] Built target opencv_cudaarithm[ 85%] Building CXX object modules/cudaarithm/CMakeFiles/opencv_test_cudaarithm.dir/test/test_event.cpp.o/home/pairman/Downloads/opencv40/modules/cudaarithm/test/test_event.cpp: In member function ‘void opencv_test::{anonymous}::AsyncEvent_Timing_Test::UnsafeTestBody()’:/home/pairman/Downloads/opencv40/modules/cudaarithm/test/test_event.cpp:76:195: error: could not convert ‘{BLOCKING_SYNC, (1 | 2)}’ from ‘’ to ‘const std::vectorcv::cuda::Event::CreateFlags
const std::vectorcv::cuda::Event::CreateFlags eventFlags = { cv::cuda::Event::CreateFlags::BLOCKING_SYNC , cv::cuda::Event::CreateFlags::BLOCKING_SYNC | Event::CreateFlags::DISABLE_TIMING };

   ^

modules/cudaarithm/CMakeFiles/opencv_test_cudaarithm.dir/build.make:158: recipe for target ‘modules/cudaarithm/CMakeFiles/opencv_test_cudaarithm.dir/test/test_event.cpp.o’ failed
make[2]: *** [modules/cudaarithm/CMakeFiles/opencv_test_cudaarithm.dir/test/test_event.cpp.o]Error 1
CMakeFiles/Makefile2:3014: recipe for target ‘modules/cudaarithm/CMakeFiles/opencv_test_cudaarithm.dir/all’ failed
make[1]: *** [modules/cudaarithm/CMakeFiles/opencv_test_cudaarithm.dir/all] Error 2Makefile:162: recipe for target ‘all’ failed
make: *** [all] Error 2

Previously I compiled OpenCV 3.4.17 for myself with no errors. I have no idea why the error happens.

I’m using Jetpack 4.6:

pairman@jetson:~/Downloads/opencv40/build$ jetson_release

  • NVIDIA Jetson Nano (Developer Kit Version)
    • Jetpack UNKNOWN [L4T 32.7.1]
    • NV Power Mode: MAXN - Type: 0
    • jetson_stats.service: active
  • Libraries:
    • CUDA: 10.2.300
    • cuDNN: 8.2.1.32
    • TensorRT: 8.2.1.8
    • Visionworks: 1.6.0.501
    • OpenCV: NOT_INSTALLED compiled CUDA: NO
    • VPI: ii libnvvpi1 1.2.3 arm64 NVIDIA Vision Programming Interface library
    • Vulkan: 1.2.70
      pairman@jetson:~/Downloads/opencv40/build$ uname -a
      Linux jetson 4.9.253-tegra #1 SMP PREEMPT Sat Feb 19 08:59:22 PST 2022 aarch64 aarch64 aarch64 GNU/Linux

The CMakeDownLog seems to have no issue:

pairman@jetson:~/Downloads/opencv40/build$ cat Download
#use_cache “/home/pairman/Downloads/opencv40/.cache”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_ADE_HASH_3rdparty_ade_v0_1_1f_zip”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_WECHAT_QRCODE_HASH_downloads_wechat_qrcode_detect_caffemodel”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_WECHAT_QRCODE_HASH_downloads_wechat_qrcode_detect_prototxt”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_WECHAT_QRCODE_HASH_downloads_wechat_qrcode_sr_caffemodel”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_WECHAT_QRCODE_HASH_downloads_wechat_qrcode_sr_prototxt”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_BOOSTDESC_HASH_downloads_xfeatures2d_boostdesc_bgm_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_BOOSTDESC_HASH_downloads_xfeatures2d_boostdesc_bgm_bi_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_BOOSTDESC_HASH_downloads_xfeatures2d_boostdesc_bgm_hd_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_BOOSTDESC_HASH_downloads_xfeatures2d_boostdesc_binboost_064_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_BOOSTDESC_HASH_downloads_xfeatures2d_boostdesc_binboost_128_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_BOOSTDESC_HASH_downloads_xfeatures2d_boostdesc_binboost_256_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_BOOSTDESC_HASH_downloads_xfeatures2d_boostdesc_lbgm_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_VGG_HASH_downloads_xfeatures2d_vgg_generated_48_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_VGG_HASH_downloads_xfeatures2d_vgg_generated_64_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_VGG_HASH_downloads_xfeatures2d_vgg_generated_80_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_XFEATURES2D_VGG_HASH_downloads_xfeatures2d_vgg_generated_120_i”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_DATA_HASH_share_opencv4_testdata_cv_face_face_landmark_model_dat”
#match_hash_in_cmake_cache “OCV_DOWNLOAD_NVIDIA_OPTICAL_FLOW_HASH_3rdparty_NVIDIAOpticalFlowSDK_2_0_Headers_edb50da3cf849840d680249aa6dbef248ebce2ca_zip”

And I’m using this CMake command. CMake will find the python libs automatically so I’m not giving these parameters

cmake -D BUILD_EXAMPLES=ON
-D INSTALL_C_EXAMPLES=ON
-D INSTALL_PYTHON_EXAMPLES=ON - D CMAKE_BUILD_TYPE=Release
-D CMAKE_INSTALL_PREFIX=/usr/local
-D CUDA_ARCH_BIN=5.3
-D CUDA_ARCH_PTX=
-D CUDA_FAST_MATH=ON
-D CUDNN_VERSION=‘8.0’
-D WITH_LIBV4L=ON
-D WITH_GSTREAMER=ON
-D WITH_GSTREAMER_0_10=OFF
-D WITH_QT=ON
-D WITH_TBB=ON
-D ENABLE_NEON=ON
-D OPENCV_DNN_CUDA=ON
-D OPENCV_ENABLE_NONFREE=ON
-D OPENCV_GENERATE_PKGCONFIG=ON
-D WITH_CUBLAS=ON
-D WITH_LAPACK=OFF
-D WITH_CUDA=ON
-D WITH_CUDNN=ON
-D CUDA_GENERATION=Maxwell
-D CUDA_NVCC_FLAGS="–expt-relaxed-constexpr"
-D WITH_FFMPEG=ON
-D ENABLE_FAST_MATH=ON
-D WITH_OPENGL=ON
-D BUILD_opencv_python2=ON
-D BUILD_opencv_python3=ON …

you could try ( no need to build test )
-DBUILD_PERF_TESTS=OFF
-DBUILD_TESTS=OFF

Thanks for your quick reply. I now try and see if it works.

Which compiler and version are you using?

This worked. Thanks again!

gcc version 7.5.0 (Ubuntu/Linaro 7.5.0-3ubuntu1~18.04). Thanks for your asking, though my issue has already been solved.

Cool, glad to hear it, just wanted to know as I wrote that test case. It compiles fine for me on gcc version 9.3.0 (Ubuntu 9.3.0-17ubuntu1~20.04), just trying why its not compiling.