简体   繁体   English

在linux上编译一个基本的OpenCV + Cuda程序

[英]Compiling a basic OpenCV + Cuda program on linux

I've worked with opencv on linux in the past, but not with cuda. 我过去曾在linux上使用opencv,但没有使用cuda。 I've struggled with the following compilation error for months. 几个月来,我一直在努力解决以下编译错误。 And after trying many solutions i gave up and worked with windows. 在尝试了许多解决方案后,我放弃了并使用了Windows。 However, i really want to work on linux. 但是,我真的想在linux上工作。 This is the command i'm using to compile the threshold example given on the opencv_gpu website. 这是我用来编译opencv_gpu网站上给出的阈值示例的命令。

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   

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 . 为了帮助您,我必须下载并安装CUDA 4.0 (带驱动程序4.0.21),然后在Mac OS X 10.6.8上为我的Macbook Pro下载和编译OpenCV 2.3

The sample code from OpenCV_GPU was successfully compiled on my machine through: OpenCV_GPU的示例代码已在我的机器上通过以下方式成功编译:

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 . 你错过了标志-lopencv_gpu ,它不包含在pkg-config中

This looks like a linker problem. 这看起来像链接器问题。 I don't know, if nvcc follows the same conventions as gcc , but I would try: 我不知道,如果nvcc遵循与gcc相同的约定,但我会尝试:

nvcc `pkg-config --cflags opencv` -L. nvcc`pkg-config --cflags opencv` -L。 -L/usr/local/cuda/lib -I. -L / usr / local / cuda / lib -I。 -I/usr/local/cuda/include -o threshold threshold.cpp `pkg-config --libs opencv` -lcuda -lcudart -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 gcc t.cpp -lB -lA

it means that libB depends on symbols from libA ; 这意味着libB依赖于从符号libA ; t.cpp can depend on symbols from libA and libB . t.cpp可以依赖于来自libAlibB符号。

Instead of using pkg-config in the nvcc line I would suggest just manually pointing the compiler at the opencv library and include files. 我建议只需手动将编译器指向opencv库并包含文件,而不是在nvcc行中使用pkg-config。 Perhaps you could just run pkg-config --libs opencv on the command line and copy the necessary libs into your nvcc command. 也许你可以在命令行上运行pkg-config --libs opencv并将必要的lib复制到你的nvcc命令中。 It seems nvcc is only choking on the opencv libs (it can't find them for sure!). 似乎nvcc只是在opencv libs上窒息(它无法找到它们!)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM