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   

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks a lot. adding -lopencv_gpu worked. Finally i can move on :D
@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.
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.
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.

2 Comments

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++
@bjoernz : Thankz mate it works like a charm :) Context: it's a make command for opencv gpu samples.
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!).

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.