opencv / opencv_contrib

Repository for OpenCV's extra modules
Apache License 2.0
9.37k stars 5.75k forks source link

Target "opencv_test_sfm" links to target "CUDA::cublas" but the target was not found. Perhaps a find_package() call is missing for an IMPORTED target, or an ALIAS target is missing? #3414

Closed isgallagher closed 9 months ago

isgallagher commented 1 year ago
System information (version)
Detailed description

I have Ubuntu 20.04.5 LTS installed on WSL2 on my Windows 10 machine. I followed the OpenCV installation requests, built Ceres Solver, and am attempting to build OpenCV with CUDA support. cmake completes, but it spits out a lot of errors. The first error is below.

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Jun__8_16:49:14_PDT_2022
Cuda compilation tools, release 11.7, V11.7.99
Build cuda_11.7.r11.7/compiler.31442593_0

$ nvidia-smi
Mon Jan  9 08:16:00 2023
+-----------------------------------------------------------------------------+
| NVIDIA-SMI 527.92.01    Driver Version: 528.02       CUDA Version: 12.0     |
|-------------------------------+----------------------+----------------------+
| GPU  Name        Persistence-M| Bus-Id        Disp.A | Volatile Uncorr. ECC |
| Fan  Temp  Perf  Pwr:Usage/Cap|         Memory-Usage | GPU-Util  Compute M. |
|                               |                      |               MIG M. |
|===============================+======================+======================|
|   0  NVIDIA RTX A200...  On   | 00000000:01:00.0 Off |                  N/A |
| N/A   48C    P0     8W /  40W |      0MiB /  8192MiB |      0%      Default |
|                               |                      |                  N/A |
+-------------------------------+----------------------+----------------------+

+-----------------------------------------------------------------------------+
| Processes:                                                                  |
|  GPU   GI   CI        PID   Type   Process name                  GPU Memory |
|        ID   ID                                                   Usage      |
|=============================================================================|
|  No running processes found                                                 |
+-----------------------------------------------------------------------------+

$ echo $LD_LIBRARY_PATH
:/usr/local/cuda-11.7/lib64

cmake output (snippet):
--   NVIDIA CUDA:                   YES (ver 11.7, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             87
--     NVIDIA PTX archs:
--
--   cuDNN:                         YES (ver 8.7.0)

-- Configuring done
CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1549 (add_executable):
  Target "opencv_test_sfm" links to target "CUDA::cublas" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:1304 (ocv_add_executable)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:169 (ocv_add_accuracy_tests)

Full output:

$ cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -DWITH_CUDA=ON -DOPENCV_DNN_CUDA=ON ..
-- Detected processor: x86_64
-- Could NOT find PythonInterp (missing: PYTHON_EXECUTABLE) (Required is at least version "2.7")
-- Looking for ccache - not found
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found suitable version "1.2.11", minimum required is "1.2.3")
Cleaning INTERNAL cached variable: WEBP_LIBRARY
Cleaning INTERNAL cached variable: WEBP_INCLUDE_DIR
-- The imported target "openjp2_static" references the file
   "/usr/lib/x86_64-linux-gnu/libopenjp2.a"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.

-- The imported target "openjpip_server" references the file
   "/usr/lib/x86_64-linux-gnu/libopenjpip_server.a"
but this file does not exist.  Possible reasons include:
* The file was deleted, renamed, or moved to another location.
* An install or uninstall procedure did not complete successfully.
* The installation package was faulty and contained
   "/usr/lib/x86_64-linux-gnu/openjpeg-2.1/OpenJPEGTargets.cmake"
but not all the files it references.

-- Found system OpenJPEG: openjp2 (found version "")
-- Found ZLIB: /usr/lib/x86_64-linux-gnu/libz.so (found version "1.2.11")
-- Found TBB (cmake): /usr/lib/x86_64-linux-gnu/libtbb.so.2
-- found Intel IPP (ICV version): 2020.0.0 [2020.0.0 Gold]
-- at: /home/ian/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
-- found Intel IPP Integration Wrappers sources: 2020.0.0
-- at: /home/ian/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
-- CUDA detected: 11.7
-- CUDA: Using CUDA_ARCH_BIN=8.7
-- CUDA NVCC target flags: -gencode;arch=compute_87,code=sm_87;-D_FORCE_INLINES
-- LAPACK(Atlas): LAPACK_LIBRARIES: /usr/lib/x86_64-linux-gnu/liblapack.so;/usr/lib/x86_64-linux-gnu/libcblas.so;/usr/lib/x86_64-linux-gnu/libatlas.so
-- LAPACK(Atlas): Support is enabled.
-- Could NOT find JNI (missing: JAVA_INCLUDE_PATH JAVA_INCLUDE_PATH2 JAVA_AWT_INCLUDE_PATH)
-- Could NOT find Pylint (missing: PYLINT_EXECUTABLE)
-- Could NOT find Flake8 (missing: FLAKE8_EXECUTABLE)
-- VTK is not found. Please set -DVTK_DIR in CMake to VTK build directory, or to VTK install subdirectory with VTKConfig.cmake file
-- Checking for module 'libavresample'
--   No package 'libavresample' found
-- Checking for module 'libdc1394-2'
--   No package 'libdc1394-2' found
-- freetype2:   YES (ver 23.1.17)
-- harfbuzz:    YES (ver 2.6.4)
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- Julia not found. Not compiling Julia Bindings.
-- Module opencv_ovis disabled because OGRE3D was not found
-- Found AMD headers in: /usr/include/suitesparse
-- Found AMD library: /usr/lib/x86_64-linux-gnu/libamd.so
-- Found CAMD headers in: /usr/include/suitesparse
-- Found CAMD library: /usr/lib/x86_64-linux-gnu/libcamd.so
-- Found CCOLAMD headers in: /usr/include/suitesparse
-- Found CCOLAMD library: /usr/lib/x86_64-linux-gnu/libccolamd.so
-- Found CHOLMOD headers in: /usr/include/suitesparse
-- Found CHOLMOD library: /usr/lib/x86_64-linux-gnu/libcholmod.so
-- Found COLAMD headers in: /usr/include/suitesparse
-- Found COLAMD library: /usr/lib/x86_64-linux-gnu/libcolamd.so
-- Found SPQR headers in: /usr/include/suitesparse
-- Found SPQR library: /usr/lib/x86_64-linux-gnu/libspqr.so
-- Found Config headers in: /usr/include/suitesparse
-- Found Config library: /usr/lib/x86_64-linux-gnu/libsuitesparseconfig.so
-- Found Intel Thread Building Blocks (TBB) library (2020.1 / 11101) include location: . Assuming SuiteSparseQR was compiled with TBB.
-- Adding librt to SuiteSparse_config libraries (required on Linux & Unix [not OSX] if SuiteSparse is compiled with timing).
-- Tesseract:   YES (ver 4.1.1)
-- Allocator metrics storage type: 'long long'
-- HDF5: Using hdf5 compiler wrapper to determine C configuration
-- Excluding from source files list: modules/imgproc/src/imgwarp.lasx.cpp
-- Excluding from source files list: modules/imgproc/src/resize.lasx.cpp
-- Registering hook 'INIT_MODULE_SOURCES_opencv_dnn': /home/ian/opencv/modules/dnn/cmake/hooks/INIT_MODULE_SOURCES_opencv_dnn.cmake
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.rvv.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/layers/layers_common.lasx.cpp
-- Excluding from source files list: <BUILD>/modules/dnn/int8layers/layers_common.lasx.cpp
-- imgcodecs: OpenEXR codec is disabled in runtime. Details: https://github.com/opencv/opencv/issues/21326
-- highgui: using builtin backend: QT5
-- GAPI VPL samples with VAAPI
-- Found AMD headers in: /usr/include/suitesparse
-- Found AMD library: /usr/lib/x86_64-linux-gnu/libamd.so
-- Found CAMD headers in: /usr/include/suitesparse
-- Found CAMD library: /usr/lib/x86_64-linux-gnu/libcamd.so
-- Found CCOLAMD headers in: /usr/include/suitesparse
-- Found CCOLAMD library: /usr/lib/x86_64-linux-gnu/libccolamd.so
-- Found CHOLMOD headers in: /usr/include/suitesparse
-- Found CHOLMOD library: /usr/lib/x86_64-linux-gnu/libcholmod.so
-- Found COLAMD headers in: /usr/include/suitesparse
-- Found COLAMD library: /usr/lib/x86_64-linux-gnu/libcolamd.so
-- Found SPQR headers in: /usr/include/suitesparse
-- Found SPQR library: /usr/lib/x86_64-linux-gnu/libspqr.so
-- Found Config headers in: /usr/include/suitesparse
-- Found Config library: /usr/lib/x86_64-linux-gnu/libsuitesparseconfig.so
-- Found Intel Thread Building Blocks (TBB) library (2020.1 / 11101) include location: . Assuming SuiteSparseQR was compiled with TBB.
-- Adding librt to SuiteSparse_config libraries (required on Linux & Unix [not OSX] if SuiteSparse is compiled with timing).
-- Building with NVIDIA Optical Flow API 2.0
-- Found 'misc' Python modules from /home/ian/opencv/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from /home/ian/opencv/modules/core/misc/python/package
-- Found 'gapi' Python modules from /home/ian/opencv/modules/gapi/misc/python/package
-- Found 'misc' Python modules from /home/ian/opencv/modules/python/package/extra_modules
-- Found 'mat_wrapper;utils' Python modules from /home/ian/opencv/modules/core/misc/python/package
-- Found 'gapi' Python modules from /home/ian/opencv/modules/gapi/misc/python/package
-- OpenCL samples are skipped: OpenCL SDK is required
-- SYCL/OpenCL samples are skipped: SYCL SDK is required
--    - check configuration of SYCL_DIR/SYCL_ROOT/CMAKE_MODULE_PATH
--    - ensure that right compiler is selected from SYCL SDK (e.g, clang++): CMAKE_CXX_COMPILER=/usr/bin/c++
--
-- General configuration for OpenCV 4.7.0-dev =====================================
--   Version control:               4.7.0-1-g9208dcb07c
--
--   Extra modules:
--     Location (extra):            /home/ian/opencv_contrib/modules
--     Version control (extra):     4.7.0
--
--   Platform:
--     Timestamp:                   2023-01-06T23:49:19Z
--     Host:                        Linux 5.10.102.1-microsoft-standard-WSL2 x86_64
--     CMake:                       3.16.3
--     CMake generator:             Unix Makefiles
--     CMake build tool:            /usr/bin/make
--     Configuration:               RELEASE
--
--   CPU/HW features:
--     Baseline:                    SSE SSE2 SSE3
--       requested:                 SSE3
--     Dispatched code generation:  SSE4_1 SSE4_2 FP16 AVX AVX2 AVX512_SKX
--       requested:                 SSE4_1 SSE4_2 AVX FP16 AVX2 AVX512_SKX
--       SSE4_1 (18 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 (5 files):             + SSSE3 SSE4_1 POPCNT SSE4_2 AVX
--       AVX2 (34 files):           + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
--       AVX512_SKX (8 files):      + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2 AVX_512F AVX512_COMMON AVX512_SKX
--
--   C/C++:
--     Built as dynamic libs?:      YES
--     C++ standard:                11
--     C++ Compiler:                /usr/bin/c++  (ver 9.4.0)
--     C++ flags (Release):         -fsigned-char -ffast-math -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -O3 -DNDEBUG  -DNDEBUG
--     C++ flags (Debug):           -fsigned-char -ffast-math -W -Wall -Wreturn-type -Wnon-virtual-dtor -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wundef -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wuninitialized -Wsuggest-override -Wno-delete-non-virtual-dtor -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -fvisibility-inlines-hidden -g  -O0 -DDEBUG -D_DEBUG
--     C Compiler:                  /usr/bin/cc
--     C flags (Release):           -fsigned-char -ffast-math -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -O3 -DNDEBUG  -DNDEBUG
--     C flags (Debug):             -fsigned-char -ffast-math -W -Wall -Wreturn-type -Waddress -Wsequence-point -Wformat -Wformat-security -Wmissing-declarations -Wmissing-prototypes -Wstrict-prototypes -Wundef -Winit-self -Wpointer-arith -Wshadow -Wuninitialized -Wno-comment -Wimplicit-fallthrough=3 -Wno-strict-overflow -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -ffunction-sections -fdata-sections  -msse -msse2 -msse3 -fvisibility=hidden -g  -O0 -DDEBUG -D_DEBUG
--     Linker flags (Release):      -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined
--     Linker flags (Debug):        -Wl,--exclude-libs,libippicv.a -Wl,--exclude-libs,libippiw.a   -Wl,--gc-sections -Wl,--as-needed -Wl,--no-undefined
--     ccache:                      NO
--     Precompiled headers:         NO
--     Extra dependencies:          m pthread cudart_static -lpthread dl rt nppc nppial nppicc nppidei nppif nppig nppim nppist nppisu nppitc npps cublas cudnn_cnn_infer_static_v8 cufft -L/usr/local/cuda-11.7/lib64 -L/usr/lib/x86_64-linux-gnu
--     3rdparty dependencies:
--
--   OpenCV modules:
--     To be built:                 alphamat aruco barcode bgsegm bioinspired calib3d ccalib core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv datasets dnn dnn_objdetect dnn_superres dpm face features2d flann freetype fuzzy gapi hdf hfs highgui img_hash imgcodecs imgproc intensity_transform line_descriptor mcc ml objdetect optflow phase_unwrapping photo plot python3 quality rapid reg rgbd saliency sfm shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab wechat_qrcode xfeatures2d ximgproc xobjdetect xphoto
--     Disabled:                    world
--     Disabled by dependency:      -
--     Unavailable:                 java julia matlab ovis python2 viz
--     Applications:                tests perf_tests examples apps
--     Documentation:               NO
--     Non-free algorithms:         YES
--
--   GUI:                           QT5
--     QT:                          YES (ver 5.12.8 )
--       QT OpenGL support:         YES (Qt5::OpenGL 5.12.8)
--     GTK+:                        YES (ver 3.24.20)
--       GThread :                  YES (ver 2.64.6)
--       GtkGlExt:                  YES (ver 1.2.0)
--     OpenGL support:              YES (/usr/lib/x86_64-linux-gnu/libGL.so /usr/lib/x86_64-linux-gnu/libGLU.so)
--     VTK support:                 NO
--
--   Media I/O:
--     ZLib:                        /usr/lib/x86_64-linux-gnu/libz.so (ver 1.2.11)
--     JPEG:                        /usr/lib/x86_64-linux-gnu/libjpeg.so (ver 80)
--     WEBP:                        build (ver encoder: 0x020f)
--     PNG:                         /usr/lib/x86_64-linux-gnu/libpng.so (ver 1.6.37)
--     TIFF:                        /usr/lib/x86_64-linux-gnu/libtiff.so (ver 42 / 4.1.0)
--     JPEG 2000:                   OpenJPEG (ver 2.3.1)
--     OpenEXR:                     build (ver 2.3.0)
--     HDR:                         YES
--     SUNRASTER:                   YES
--     PXM:                         YES
--     PFM:                         YES
--
--   Video I/O:
--     DC1394:                      NO
--     FFMPEG:                      YES
--       avcodec:                   YES (58.54.100)
--       avformat:                  YES (58.29.100)
--       avutil:                    YES (56.31.100)
--       swscale:                   YES (5.5.100)
--       avresample:                NO
--     GStreamer:                   YES (1.16.3)
--     v4l/v4l2:                    YES (linux/videodev2.h)
--
--   Parallel framework:            TBB (ver 2020.1 interface 11101)
--
--   Trace:                         YES (with Intel ITT)
--
--   Other third-party libraries:
--     Intel IPP:                   2020.0.0 Gold [2020.0.0]
--            at:                   /home/ian/opencv/build/3rdparty/ippicv/ippicv_lnx/icv
--     Intel IPP IW:                sources (2020.0.0)
--               at:                /home/ian/opencv/build/3rdparty/ippicv/ippicv_lnx/iw
--     VA:                          YES
--     Lapack:                      YES (/usr/lib/x86_64-linux-gnu/liblapack.so /usr/lib/x86_64-linux-gnu/libcblas.so /usr/lib/x86_64-linux-gnu/libatlas.so)
--     Eigen:                       YES (ver 3.3.7)
--     Custom HAL:                  NO
--     Protobuf:                    build (3.19.1)
--
--   NVIDIA CUDA:                   YES (ver 11.7, CUFFT CUBLAS FAST_MATH)
--     NVIDIA GPU arch:             87
--     NVIDIA PTX archs:
--
--   cuDNN:                         YES (ver 8.7.0)
--
--   OpenCL:                        YES (INTELVA)
--     Include path:                /home/ian/opencv/3rdparty/include/opencl/1.2
--     Link libraries:              Dynamic load
--
--   Python 3:
--     Interpreter:                 /home/ian/pyenvs/opencv_cuda/bin/python3 (ver 3.8.10)
--     Libraries:                   /usr/lib/x86_64-linux-gnu/libpython3.8.so (ver 3.8.10)
--     numpy:                       /home/ian/pyenvs/opencv_cuda/lib/python3.8/site-packages/numpy/core/include (ver 1.24.1)
--     install path:                lib/python3.8/site-packages/cv2/python-3.8
--
--   Python (for build):            /home/ian/pyenvs/opencv_cuda/bin/python
--
--   Java:
--     ant:                         NO
--     JNI:                         NO
--     Java wrappers:               NO
--     Java tests:                  NO
--
--   Install to:                    /usr/local
-- -----------------------------------------------------------------
--
-- Configuring done
CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1549 (add_executable):
  Target "opencv_test_sfm" links to target "CUDA::cublas" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:1304 (ocv_add_executable)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:169 (ocv_add_accuracy_tests)

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1549 (add_executable):
  Target "opencv_test_sfm" links to target "CUDA::cudart" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:1304 (ocv_add_executable)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:169 (ocv_add_accuracy_tests)

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1549 (add_executable):
  Target "opencv_test_sfm" links to target "CUDA::cusolver" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:1304 (ocv_add_executable)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:169 (ocv_add_accuracy_tests)

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1549 (add_executable):
  Target "opencv_test_sfm" links to target "CUDA::cusparse" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:1304 (ocv_add_executable)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:169 (ocv_add_accuracy_tests)

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1560 (add_library):
  Target "opencv_sfm" links to target "CUDA::cublas" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:966 (ocv_add_library)
  /home/ian/opencv/cmake/OpenCVModule.cmake:882 (_ocv_create_module)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:150 (ocv_create_module)

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1560 (add_library):
  Target "opencv_sfm" links to target "CUDA::cudart" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:966 (ocv_add_library)
  /home/ian/opencv/cmake/OpenCVModule.cmake:882 (_ocv_create_module)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:150 (ocv_create_module)

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1560 (add_library):
  Target "opencv_sfm" links to target "CUDA::cusolver" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:966 (ocv_add_library)
  /home/ian/opencv/cmake/OpenCVModule.cmake:882 (_ocv_create_module)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:150 (ocv_create_module)

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1560 (add_library):
  Target "opencv_sfm" links to target "CUDA::cusparse" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:966 (ocv_add_library)
  /home/ian/opencv/cmake/OpenCVModule.cmake:882 (_ocv_create_module)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:150 (ocv_create_module)

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/correspondence/CMakeLists.txt:9 (ADD_LIBRARY):
  Target "correspondence" links to target "CUDA::cublas" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/correspondence/CMakeLists.txt:9 (ADD_LIBRARY):
  Target "correspondence" links to target "CUDA::cudart" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/correspondence/CMakeLists.txt:9 (ADD_LIBRARY):
  Target "correspondence" links to target "CUDA::cusolver" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/correspondence/CMakeLists.txt:9 (ADD_LIBRARY):
  Target "correspondence" links to target "CUDA::cusparse" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt:19 (ADD_LIBRARY):
  Target "multiview" links to target "CUDA::cublas" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt:19 (ADD_LIBRARY):
  Target "multiview" links to target "CUDA::cudart" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt:19 (ADD_LIBRARY):
  Target "multiview" links to target "CUDA::cusolver" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt:19 (ADD_LIBRARY):
  Target "multiview" links to target "CUDA::cusparse" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/simple_pipeline/CMakeLists.txt:18 (ADD_LIBRARY):
  Target "simple_pipeline" links to target "CUDA::cublas" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/simple_pipeline/CMakeLists.txt:18 (ADD_LIBRARY):
  Target "simple_pipeline" links to target "CUDA::cudart" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/simple_pipeline/CMakeLists.txt:18 (ADD_LIBRARY):
  Target "simple_pipeline" links to target "CUDA::cusolver" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/simple_pipeline/CMakeLists.txt:18 (ADD_LIBRARY):
  Target "simple_pipeline" links to target "CUDA::cusparse" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1560 (add_library):
  Target "opencv_sfm" links to target "CUDA::cublas" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:966 (ocv_add_library)
  /home/ian/opencv/cmake/OpenCVModule.cmake:882 (_ocv_create_module)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:150 (ocv_create_module)

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1560 (add_library):
  Target "opencv_sfm" links to target "CUDA::cudart" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:966 (ocv_add_library)
  /home/ian/opencv/cmake/OpenCVModule.cmake:882 (_ocv_create_module)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:150 (ocv_create_module)

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1560 (add_library):
  Target "opencv_sfm" links to target "CUDA::cusolver" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:966 (ocv_add_library)
  /home/ian/opencv/cmake/OpenCVModule.cmake:882 (_ocv_create_module)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:150 (ocv_create_module)

CMake Error at /home/ian/opencv/cmake/OpenCVUtils.cmake:1560 (add_library):
  Target "opencv_sfm" links to target "CUDA::cusparse" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv/cmake/OpenCVModule.cmake:966 (ocv_add_library)
  /home/ian/opencv/cmake/OpenCVModule.cmake:882 (_ocv_create_module)
  /home/ian/opencv_contrib/modules/sfm/CMakeLists.txt:150 (ocv_create_module)

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/correspondence/CMakeLists.txt:9 (ADD_LIBRARY):
  Target "correspondence" links to target "CUDA::cublas" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/correspondence/CMakeLists.txt:9 (ADD_LIBRARY):
  Target "correspondence" links to target "CUDA::cudart" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/correspondence/CMakeLists.txt:9 (ADD_LIBRARY):
  Target "correspondence" links to target "CUDA::cusolver" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/correspondence/CMakeLists.txt:9 (ADD_LIBRARY):
  Target "correspondence" links to target "CUDA::cusparse" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt:19 (ADD_LIBRARY):
  Target "multiview" links to target "CUDA::cublas" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt:19 (ADD_LIBRARY):
  Target "multiview" links to target "CUDA::cudart" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt:19 (ADD_LIBRARY):
  Target "multiview" links to target "CUDA::cusolver" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/multiview/CMakeLists.txt:19 (ADD_LIBRARY):
  Target "multiview" links to target "CUDA::cusparse" but the target was not
  found.  Perhaps a find_package() call is missing for an IMPORTED target, or
  an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/simple_pipeline/CMakeLists.txt:18 (ADD_LIBRARY):
  Target "simple_pipeline" links to target "CUDA::cublas" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/simple_pipeline/CMakeLists.txt:18 (ADD_LIBRARY):
  Target "simple_pipeline" links to target "CUDA::cudart" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/simple_pipeline/CMakeLists.txt:18 (ADD_LIBRARY):
  Target "simple_pipeline" links to target "CUDA::cusolver" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

CMake Error at /home/ian/opencv_contrib/modules/sfm/src/libmv_light/libmv/simple_pipeline/CMakeLists.txt:18 (ADD_LIBRARY):
  Target "simple_pipeline" links to target "CUDA::cusparse" but the target
  was not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?

-- Generating done
CMake Generate step failed.  Build files cannot be regenerated correctly.
Steps to reproduce
1. On a Windows 10 64 bit machine, 22h2, install Ubuntu 20.04 on WSL2
2. Update Ubuntu
3. Follow these steps to set up CUDA, https://docs.nvidia.com/cuda/wsl-user-guide/index.html
4. Build Ceres Solver and install.
5. Follow the following steps for building OpenCV:

git clone https://github.com/opencv/opencv.git
cd opencv && git checkout 9208dcb07c015e1fda44e40bb07b43c700b4bf46
cd ..
git clone https://github.com/opencv/opencv_contrib.git
cd opencv_contrib && git checkout e247b680a6bd396f110274b6c214406a93171350
cd ../opencv && mkdir build && cd build
cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -DWITH_CUDA=ON -DOPENCV_DNN_CUDA=ON ..
cudawarped commented 1 year ago

OpenCV does not currently support targets resulting from FindCUDAToolkit.

It looks like Ceras Solver exports these targets regardless of which version of CMake is being used. The only thing I can suggest is trying to build against https://github.com/opencv/opencv/pull/23021 and https://github.com/opencv/opencv_contrib/pull/3400 to see if it solves your issue.

Just out of interest why are you building for Compute 8.7 on WSL are you going to run on a Jetson?

isgallagher commented 1 year ago

Hi @cudawarped thanks for sharing those PRs. I will try to build against those and see if it works for me. I will be targeting the NVIDIA Jetson AGX Xavier, but I also have a need for local inference for my proof of concept. I started out using OpenCV on Windows, but the image processing is taking too long on the CPU, so I went down the road of building with support for CUDA, and decided to build it on WSL as I thought it would be easier 🤣

cudawarped commented 1 year ago

I just thought u'll have to build with cmake 3.18+ for OpenCV to use those targets.

but I also have a need for local inference for my proof of concept

Let me know if it works and don't forget to build for your A2000 aswell, I think its Compute 8.6 (-DCUDA_ARCH_BIN=8.6).

isgallagher commented 1 year ago

That's right. Looks like the Jetson is SM_72 as well, so I was way off base there.

I am still getting the same errors when using your PRs code.

CMake Error at /home/ian/opencv-pr23021/cmake/OpenCVUtils.cmake:1556 (add_executable):
  Target "opencv_test_sfm" links to target "CUDA::cublas" but the target was
  not found.  Perhaps a find_package() call is missing for an IMPORTED
  target, or an ALIAS target is missing?
Call Stack (most recent call first):
  /home/ian/opencv-pr23021/cmake/OpenCVModule.cmake:1304 (ocv_add_executable)
  /home/ian/opencv_contrib-pr3400/modules/sfm/CMakeLists.txt:169 (ocv_add_accuracy_tests)

New command line is

cmake -DOPENCV_EXTRA_MODULES_PATH=../../opencv_contrib-pr3400/modules -DWITH_CUDA=ON -DOPENCV_DNN_CUDA=ON -DCUDA_ARCH_BIN=8.6 -DCUDAToolkit_LIBRARY_ROOT=/usr/local/cuda-11.7/lib64 -DENABLE_CUDA_FIRST_CLASS_LANGUAGE=ON ..
cudawarped commented 1 year ago

If I use OpenCV with CMake 3.24 then I don't get any CMake errors regarding CUDA targets however libopencv_sfm fails to link due to

undefined reference to `google::InitVLOG3__(google::SiteFlag, int, char const*, int)'

isgallagher commented 1 year ago

I have cmake version 3.16.3 installed on the system. I downloaded cmake-3.24.3 and that worked. Thank you!

I should say I did update the CMakeList.txt for sfm. I'm not sure if it was needed but it didn't give me the error you posted.

At line 109

### CREATE OPENCV SFM MODULE ###

set(extra_dependencies "")
set(optional_dependencies "")
if(ENABLE_CUDA_FIRST_CLASS_LANGUAGE)
  list(APPEND extra_dependencies CUDA::cudart_static CUDA::nppial${CUDA_LIB_EXT} CUDA::nppc${CUDA_LIB_EXT} CUDA::nppitc${CUDA_LIB_EXT} CUDA::nppig${CUDA_LIB_EXT} CUDA::nppist${CUDA_LIB_EXT} CUDA::nppidei${CUD>  if(HAVE_CUBLAS)
    list(APPEND optional_dependencies CUDA::cublas${CUDA_LIB_EXT})
    if(NOT CUDA_VERSION VERSION_LESS 10.1)
      list(APPEND optional_dependencies CUDA::cublasLt${CUDA_LIB_EXT})
    endif()
  endif()
  if(HAVE_CUFFT)
    # static version requires seperable compilation which is incompatible with opencv's current library structure
    list(APPEND optional_dependencies CUDA::cufft)
  endif()
else()
  if(HAVE_CUBLAS)
    list(APPEND optional_dependencies ${CUDA_cublas_LIBRARY})
  endif()
  if(HAVE_CUFFT)
    list(APPEND optional_dependencies ${CUDA_cufft_LIBRARY})
  endif()
endif()

ocv_add_module(sfm
  opencv_core
  opencv_calib3d
  opencv_features2d
  opencv_xfeatures2d
  opencv_imgcodecs
  ${extra_dependencies}
  ${optional_dependencies}
  WRAP python
)
cudawarped commented 1 year ago

That's great although I'm not sure that modification is necessary as Ceres should be exporting those targets. I didn't get missing CUDA target errors without it did you?

cudawarped commented 1 year ago

@isgallagher would it be possible to check if you can build OpenCV without modifying CMakeList.txt for sfm to see if the PR's fix the issue for you.

Either way this looks like an issue with Ceras not OpenCV so should probably be closed. The developers are exporting targets for CMake >= 3.18 when it is built with CMake < 3.18. I am sure there is a reason for this although I am not sure what it is. That is if you are compiling on a machine with CMake 3.16 I don't think you would expect to build a library which can only be imported successfully with CMake >=3.18.

isgallagher commented 1 year ago

Sorry, I already blew away the build environment as it turns out I don't need OpenCV.