2

I've worked with opencv on linux in the past, but not with cuda. I've struggled with the following compilation error for months. And after trying many solutions i gave up and worked with windows. However, i really want to work on linux. This is the command i'm using to compile the threshold example given on the opencv_gpu website.

nvcc `pkg-config --libs opencv` -L. -L/usr/local/cuda/lib -lcuda -lcudart `pkg-config --cflags opencv` -I. -I/usr/local/cuda/include threshold.cpp -o threshold

here is the error:

/tmp/tmpxft_0000171b_00000000-1_threshold.o: In function `main':
threshold.cpp:(.text+0x124): undefined reference to `cv::gpu::Stream::Null()'
threshold.cpp:(.text+0x156): undefined reference to `cv::gpu::threshold(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, int, cv::gpu::Stream&)'
threshold.cpp:(.text+0x16d): undefined reference to `cv::gpu::GpuMat::download(cv::Mat&) const'
/tmp/tmpxft_0000171b_00000000-1_threshold.o: In function `cv::gpu::GpuMat::GpuMat(cv::Mat const&)':
threshold.cpp:(.text._ZN2cv3gpu6GpuMatC1ERKNS_3MatE[cv::gpu::GpuMat::GpuMat(cv::Mat const&)]+0x63): undefined reference to `cv::gpu::GpuMat::upload(cv::Mat const&)'
/tmp/tmpxft_0000171b_00000000-1_threshold.o: In function `cv::gpu::GpuMat::~GpuMat()':
threshold.cpp:(.text._ZN2cv3gpu6GpuMatD1Ev[cv::gpu::GpuMat::~GpuMat()]+0xd): undefined reference to `cv::gpu::GpuMat::release()'                                        
collect2: ld returned 1 exit status                                                                                                                                     
make: *** [all] Error 1   
karlphillip
  • 92,053
  • 36
  • 243
  • 426
user779328
  • 105
  • 1
  • 2
  • 10

3 Answers3

9

In order to help you I had to download and install CUDA 4.0 (with driver 4.0.21) and then download and compiled OpenCV 2.3 for my Macbook Pro, on Mac OS X 10.6.8.

The sample code from OpenCV_GPU was successfully compiled on my machine through:

g++ threshold.cpp -o threshold `pkg-config --cflags --libs opencv` -lopencv_gpu

You were missing the flag -lopencv_gpu , which is not included by pkg-config.

karlphillip
  • 92,053
  • 36
  • 243
  • 426
  • Thanks a lot. adding -lopencv_gpu worked. Finally i can move on :D – user779328 Jul 28 '11 at 09:29
  • @karlphillip I am getting the following error after adding -lopencv_gpu to the command line ---- **/usr/bin/ld: cannot find -lopencv_gpu**. Can you suggest the solution to this issue. – MuneshSingh Jun 04 '17 at 19:30
  • That's a different issue from what was stated on this question. Feel free to click on the **Ask Question** button and make a new one. – karlphillip Jun 04 '17 at 20:59
1

This looks like a linker problem. I don't know, if nvcc follows the same conventions as gcc, but I would try:

nvcc `pkg-config --cflags opencv` -L. -L/usr/local/cuda/lib -I. -I/usr/local/cuda/include -o threshold threshold.cpp `pkg-config --libs opencv` -lcuda -lcudart

More in general: If you write

gcc t.cpp -lB -lA

it means that libB depends on symbols from libA; t.cpp can depend on symbols from libA and libB.

bjoernz
  • 3,852
  • 18
  • 30
  • Thanks for the quick reply. I tried that now, but gave the exact same error though... and it gives the same error if i replace nvcc with g++ – user779328 Jul 27 '11 at 13:01
  • @bjoernz : Thankz mate it works like a charm :) Context: it's a make command for opencv gpu samples. – G453 Jul 26 '16 at 05:37
1

Instead of using pkg-config in the nvcc line I would suggest just manually pointing the compiler at the opencv library and include files. Perhaps you could just run pkg-config --libs opencv on the command line and copy the necessary libs into your nvcc command. It seems nvcc is only choking on the opencv libs (it can't find them for sure!).

Marm0t
  • 921
  • 9
  • 18