linux下c程序调用cuda,关于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),然后在Mac OS X 10.6.8上为Macbook Pro下载并编译OpenCV 2.3。

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

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

您丢失了标志-lopencv_gpu,该标志未包含在pkg-config中。

非常感谢。 添加-lopencv_gpu起作用。 最后我可以继续:D

@karlphillip在将-lopencv_gpu添加到命令行后,出现以下错误---- / usr / bin / ld:找不到-lopencv_gpu。 您能为这个问题提出解决方案吗?

那与在这个问题上所说的不同。 随时单击"提问"按钮,然后重新创建一个。

建议不要在nvcc行中使用pkg-config,而是建议手动将编译器指向opencv库并包含文件。也许您可以只在命令行上运行pkg-config --libs opencv并将必要的库复制到nvcc命令中。看来nvcc只是在opencv库上窒息(它肯定找不到它们!)。

这看起来像一个链接器问题。我不知道nvcc是否遵循与gcc相同的约定,但是我会尝试:

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

一般而言:如果您写

gcc t.cpp -lB -lA

这意味着libB依赖于libA中的符号; t.cpp可以依赖于libA和libB中的符号。

感谢您的快速答复。 我现在尝试了,但是虽然给出了完全相同的错误...并且如果我用g ++替换nvcc也会给出相同的错误

@bjoernz:Thankz mate它的工作原理就像一个魅力:)上下文:它是opencv gpu样本的make命令。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值