Open
Description
System Information
when enable WITH_CUDA, the opencv_core actually requires cudart, due to the gpuMat functions. However, opencv_core target does not expose the required cudart at all. So anything link to opencv_core will fail.
ENABLE_CUDA_FIRST_CLASS_LANGUAGE=OFF is also broken, although it expose all the cuda libs, however only the cudart is static but all other is dynamic.
Detailed description
ninja: Entering directory `./build'
[1/1] Linking CXX executable opencv_core_example
FAILED: opencv_core_example
: && /usr/lib64/ccache/c++ CMakeFiles/opencv_core_example.dir/core_example.cpp.o -o opencv_core_example /home/user/opencv-4.11.0/build/lib/libopencv_core.a /home/user/opencv-4.11.0/build/lib/libopencv_cudev.a -lm -lpthread -lrt /usr/lib64/libz.so /lib64/libopenblas.so /home/user/opencv-4.11.0/build/3rdparty/lib/libittnotify.a -ldl && :
/usr/bin/ld: /home/user/opencv-4.11.0/build/lib/libopencv_core.a(gpu_mat.cu.o): in function `(anonymous namespace)::DefaultAllocator::free(cv::cuda::GpuMat*)':
tmpxft_001d20c5_00000000-6_gpu_mat.compute_75.cudafe1.cpp:(.text._ZN43_GLOBAL__N__6553ab56_10_gpu_mat_cu_71482d8916DefaultAllocator4freeEPN2cv4cuda6GpuMatE+0x9): undefined reference to `cudaFree'
Steps to reproduce
Build the opencv 4.11.0 with following cmd:
cmake -B build -G Ninja \
-DWITH_IPP=OFF -DWITH_WEBP=OFF \
-DWITH_JASPER=OFF -DWITH_TIFF=OFF \
-DWITH_OPENJPEG=OFF -DWITH_OPENEXR=OFF \
-DENABLE_PIC=ON -DOPENCV_ENABLE_NONFREE=OFF \
-DWITH_CUDA=ON -DWITH_EIGEN=OFF \
-DWITH_GSTREAMER=OFF -DBUILD_opencv_python3=OFF \
-DBUILD_opencv_python2=OFF -DWITH_1394=OFF \
-DWITH_PROTOBUF=OFF -DWITH_CAROTENE=OFF \
-DBUILD_TESTS=OFF -DBUILD_PERF_TESTS=OFF \
-DBUILD_opencv_apps=OFF -DBUILD_JAVA=OFF \
-DBUILD_opencv_dnn=OFF -DBUILD_opencv_gapi=OFF \
-DWITH_ADE=OFF \
-DOPENCV_EXTRA_MODULES_PATH="contrib/modules/cudev;contrib/modules/cudaarithm" \
-DOPENCV_CMAKE_CUDA_DEBUG=1 \
-DOPENCV_CUDA_DETECTION_NVCC_FLAGS=-allow-unsupported-compiler \
-DCUDA_NVCC_FLAGS=-allow-unsupported-compiler \
-DWITH_AVIF=OFF \
-DENABLE_CUDA_FIRST_CLASS_LANGUAGE=ON \
-DCMAKE_CUDA_ARCHITECTURES="61;75" \
-DBUILD_SHARED_LIBS=OFF
Then build a simple project
cmake_minimum_required(VERSION 3.30)
project(OpenCV_CUDA_Example)
# Find OpenCV (this will use the OpenCVConfig.cmake from the build directory)
find_package(OpenCV REQUIRED)
add_executable(opencv_core_example core_example.cpp)
# Link only opencv_core
target_link_libraries(opencv_core_example opencv_core)
// core_example.cpp
#include <opencv2/core.hpp> // Only include opencv_core
#include <iostream>
int main() {
// Create two 3x3 matrices filled with 1.0 and 2.0 respectively
cv::Mat mat1 = cv::Mat::ones(3, 3, CV_32FC1) * 1.0f; // 3x3 matrix filled with 1.0
cv::Mat mat2 = cv::Mat::ones(3, 3, CV_32FC1) * 2.0f; // 3x3 matrix filled with 2.0
// Perform matrix addition
cv::Mat result;
cv::add(mat1, mat2, result);
// Print the result matrix to the console
std::cout << "Matrix 1:" << std::endl << mat1 << std::endl;
std::cout << "Matrix 2:" << std::endl << mat2 << std::endl;
std::cout << "Result (Matrix 1 + Matrix 2):" << std::endl << result << std::endl;
return 0;
}
mkdir -p ./build
set -e
set -x
cmake --version
cmake -B build -G Ninja \
-DOpenCV_DIR=../opencv-4.11.0/build \
2>&1 | tee cmake.log
ninja -C ./build 2>&1 | tee build.log
Issue submission checklist
- I report the issue, it's not a question
- I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
- I updated to the latest OpenCV version and the issue is still there
- There is reproducer code and related data files (videos, images, onnx, etc)
Metadata
Metadata
Assignees
Labels
No labels