Need help ASAP for error: "undefined reference to cv::cuda::xxxx " each time referencing to a “cv::cuda::xxx” function

I am using Cuda on my laptop and have installed Cuda, cudnn libraries, the drivers, as well OpenCV by enabling Cuda xxx.

Attached are :

  • the output of the Nvidia-smi terminal command
  • the result from print(cv2.getBuildInformation()) describing how OpenCV is built from the source OpenCv_Installation_Summary.txt (17.4 KB)
  • example of a program; please keep in mind that the same problem subsists when using cv::cuda::threshold(src, dst, 128.0, 255.0, cv::THRESH_BINARY); cv::Ptrcv::cuda::Convolution conv = cv::cuda::createConvolution(cv::Size(kern_height, kern_width));or any other cv::cuda functions main.cpp.txt (1.1 KB)

I am running the following terminal command to run my program:

$ g++ -o opencv_dnn_cuda_test_cpp main.cpp -I/usr/local/include/opencv4 -L/usr/local/lib -lopencv_core -lopencv_dnn -lopencv_highgui -lopencv_imgcodecs -lopencv_videoio -lopencv_shape

It gives an undefined reference to ‘cv::cuda::…’ “ error each time I am referring to any sort of “cv::cuda::xxx” function; here is one example:

/usr/bin/ld: /tmp/ccsDCArl.o: in function main':** **main.cpp:(.text+0xfa): undefined reference to cv::cuda::createCLAHE(double, cv::Size_)’

However, uploading and downloading images from/to the gpu seems to work
I would appreciate it if you could help me to solve this issue as soon as possible.
Thank you for your help,

NVIDIA doesn’t develop, maintain, or support cv::cuda.

undefined reference is commonly an indication of a link-time failure, due to not linking against needed libraries.

In the case of cv::cuda::createCLAHE this appears to be part of the cv::cuda imgproc module, and you might try linking against that module, e.g. -lopencv_imgproc or similar. It may also be necessary to link against a cuda-specific module./library such as -lopencv_cudaimgproc See here for a similar write-up.

OpenCV linking can be fairly involved, due to the large number of libraries possible. This people often use cmake or pkg-config to assist.

I won’t be able to give any recipes.

1 Like

Hi Robert, Thank you for your quick reply. It seems that adding lopencv_cudaimgproc eliminate the error message.
SInce I am a debutant in Cuda, could you please tell me how did you figure out that was the missing library and where should I be looking?

I am going to try with other cv::cuda:: function to see if that works too

By the way, I indeed used Cmake and pkg-config by going through similar steps describes herein to install OpenCV:

Again thank you for your help!

Hi Robert,

Again thank you for your valuable help!
In case I would like to use cv::cuda::Convolution should I add -lopencv_cudaarithm based on the following link? OpenCV: cv::cuda::Convolution Class Reference
?
Thank you for your time,

Sorry, I don’t wish to be a library look-up engine for you w.r.t. OpenCV. I personally find OpenCV difficult to use. The difficulty in locating the correct answer for a question like this is just one of the examples I can think of, for difficulty using OpenCV. Good luck!

The general process I used is as follows (I’ve already given you some links/waypoints):

  1. find the module for the undefined reference. A google search usually suffices here. When I do a google search on cv::cuda::createCLAHE this page is among the top hits. On that page I observe the necessary include file happens to be : #include <opencv2/cudaimgproc.hpp>

  2. I know from experience, I guess, that openCV on linux often has library names structured like libopencv_<module>.so. Even without “experience” you should probably be able to deduce this just by studying the compile command you placed in your question.

  3. From there, a bit of google searching eventually confirms that there does seem to be a library called libopencv_cudaimgproc.so. So that was the basis of my suggestion.

To be fair, although I don’t think its quite as difficult as OpenCV, its not always that obvious to figure out which npp library a particular npp function call belongs to. But since I have a number of systems with CUDA and npp installed on them, it’s relatively simple for me to quickly discover that with a few grep commands. If you had a proper, expansive build of OpenCV installed on your machine, and you knew the directory structure of it, you could simply grep the undefined reference. One or more of the libraries you grep will indicate that the binary file matches. This will then tell you which additional library(s) need to be linked. Such a process may require a few iterations.

1 Like

Thank you, Robert, for your detailed feedback, time, and quick response.
I am using OpenCV to conduct arithmetic operations on images using NVIDIA GPU to improve the computation time.

Is there an easy way to make arithmetic operations on 2D matrix representation of images using only Cuda libraries or a user-friendly alternative to OpenCV?

Best regards

I doubt there is anything that duplicates OpenCV exactly. I already mentioned npp, it ships with the CUDA toolkit. Don’t know if it is “user-friendly”.

1 Like

Thank you Robert!

Also, I have the following warning sometimes:

[ WARN:0] global /home/installation/OpenCV/opencv/modules/dnn/src/cuda4dnn/init.hpp (42) checkVersions CUDART version 11050 reported by cuDNN 8301 does not match with the version reported by CUDART 10010

  1. Does this affect the execution of the program?

  2. Do you have any advice on how to fix it?
    (I have both CUDA Driver Version / Runtime Version 11.50 / 10.10 installed)

  1. I don’t know. I would assume a WARN allows things to continue.
  2. It appears to be a mismatch of some sort between CUDA 11.5 and CUDA 10.1. If you are attempting to use cuDNN 8.3 with CUDA 10.1, that could be a possible explanation. To fix it, you would want to use a version of CUDA that your cuDNN built was built “against”.