将libopencv_gpu.so与OpenCV链接时的未定义引用

时间:2014-08-14 15:41:14

标签: c++ opencv

尝试编译单个.cpp文件时出错

Main.cpp的:

#include "opencv2/core/core_c.h"
#include "opencv2/core/core.hpp"
#include "opencv2/flann/miniflann.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/features2d/features2d.hpp"
#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/calib3d/calib3d.hpp"
#include "opencv2/ml/ml.hpp"
#include "opencv2/highgui/highgui_c.h"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include <opencv2/gpu/gpu.hpp>
#include <iostream>

int main(int argc, char* argv[])
{
    cv::VideoCapture capture = cv::VideoCapture(argv[1]);
    cv::gpu::GpuMat gpu_frame,gpu_frame_binary;
    cv::Mat frame;
    int threshold_value = 80;
    int threshold_type = 0;
  while (1)
     {
        capture >> frame;
        gpu_frame.upload(frame);
        if (!frame.data)             
            break;

        cv::gpu::threshold(gpu_frame, gpu_frame_binary, threshold_value, 255, threshold_type);
      }
   return 0;
 }

使用这些选项构建的OpenCV:

cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_V4L=ON -D WITH_GSTREAMER=ON -D WITH_OPENEXR=ON -D WITH_UNICAP=ON -D BUILD_PYTHON_SUPPORT=ON -D INSTALL_C_EXAMPLES=ON -D BUILD_EXAMPLES=ON -D ENABLE_SSE2=ON -D WITH_CUDA=ON ..

用于编译的命令:

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

我得到的错误:

/usr/local/lib/libopencv_gpu.so: undefined reference to `cv::gpu::convertTo(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, CUstream_st*)'
/usr/local/lib/libopencv_gpu.so: undefined reference to `cv::gpu::setTo(cv::gpu::GpuMat&, cv::Scalar_<double>, cv::gpu::GpuMat const&, CUstream_st*)'
/usr/local/lib/libopencv_gpu.so: undefined reference to `cv::gpu::setTo(cv::gpu::GpuMat&, cv::Scalar_<double>, CUstream_st*)'
collect2: error: ld returned 1 exit status

当我尝试在没有-lopencv_gpu选项的情况下编译时,我得到的错误如下:

main.cpp:61: undefined reference to `cv::gpu::threshold(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, int, cv::gpu::Stream&)'

任何想法可能出错?

PS重要的是要注意我第一次构建没有cuda的opencv,然后决定我想尝试cuda并使用cuda选项构建它,并且sudo make install.我认为它会覆盖之前安装的内容,但也许出了点问题?

使用Nvidia卡在Fedora 20上运行。

1 个答案:

答案 0 :(得分:1)

我遇到了同样的问题 为了解决这个问题,我刚刚删除了libopencv_gpu.so.2.4

中的libopencv_gpu.so.2.4.10/usr/local/lib/.