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

标签 c++ c linux opencv cuda

我过去曾在 linux 上使用过 opencv,但没有使用过 cuda。几个月来,我一直在为以下编译错误而苦苦挣扎。在尝试了许多解决方案后,我放弃了并使用 Windows。但是,我真的很想在 Linux 上工作。这是我用来编译 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

这里是错误:

/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   

最佳答案

为了帮助您,我必须下载并安装 CUDA 4.0(带有驱动程序 4.0.21),然后为我的 Macbook Pro 下载并编译 OpenCV 2.3,在Mac OS X 10.6.8

示例代码来自 OpenCV_GPU通过以下方式在我的机器上成功编译:

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

您缺少标志 -lopencv_gpu ,它不包含在 pkg-config 中。

关于c++ - 在 linux 上编译一个基本的 OpenCV + Cuda 程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6842197/

相关文章:

c - pthread 互斥体不工作,每次都获取一个随机值

c - 位域和 union 大小

linux - 如何进行增量时间跳跃以避免数据丢失

c++ - 没有 OpenGL 的纹理映射

c++ - 基于条件的 Istream 引用

c++ - 为什么在 C/C++ 中重复包含一些头文件?

c - C 中结构体定义的变体

type_info 的 C++ 特定类型

linux - 设置jenkins进程的umask

c++ - 比 stat() 更好的方法来查找目录中的文件?