0

I get an error when trying to compile a single .cpp file

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 built with these options:

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 ..

Command used to compile:

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

And the error I get:

/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

When I try to compile without the -lopencv_gpu option I get errors like:

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

Any ideas what might be wrong?

P.S It may be important to note that I first built opencv without cuda, then decided that I wanted to try cuda and built it with cuda option on, and did sudo make install. I thought it would overwrite what was previously installed, but maybe something went wrong there?

Running on Fedora 20, with Nvidia card.

5
  • What does nm /usr/local/lib/libopencv_gpu.so | grep convertTo* returns? Aug 14, 2014 at 18:19
  • ` U _ZN2cv3gpu9convertToERKNS0_6GpuMatERS1_ddP11CUstream_st U _ZNK2cv3gpu6GpuMat9convertToERS1_idd U _ZNK2cv3Mat9convertToERKNS_12_OutputArrayEidd `
    – Bndr
    Aug 14, 2014 at 18:32
  • Please feed that info to c++filtto demangle it. Aug 14, 2014 at 19:53
  • U cv::gpu::convertTo(cv::gpu::GpuMat const&, cv::gpu::GpuMat&, double, double, CUstream_st*) U cv::gpu::GpuMat::convertTo(cv::gpu::GpuMat&, int, double, double) const U cv::Mat::convertTo(cv::_OutputArray const&, int, double, double) const
    – Bndr
    Aug 18, 2014 at 10:06
  • Are there other libopencv*.so libraries in /usr/local/lib ? You could chekc them one by one to see where convertTo() is defined (nm shall report something like T cv::gpu::convertTo() ) Feb 3, 2015 at 1:06

1 Answer 1

1

I encountered the same problem.
To solve it I just deleted libopencv_gpu.so.2.4 and libopencv_gpu.so.2.4.10 in /usr/local/lib/.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.