title: Undefined reference when linking libopencv_gpu.so with OpenCV
body: <p>I get an error when trying to compile a single .cpp file</p>
  
  <p>Main.cpp:</p>
  
  <pre><code>#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 &lt;opencv2/gpu/gpu.hpp&gt;
  #include &lt;iostream&gt;
  
  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 &gt;&gt; frame;
          gpu_frame.upload(frame);
          if (!frame.data)             
              break;
  
          cv::gpu::threshold(gpu_frame, gpu_frame_binary, threshold_value, 255, threshold_type);
        }
     return 0;
   }
  </code></pre>
  
  <p>OpenCV built with these options:</p>
  
  <pre><code>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 ..
  </code></pre>
  
  <p>Command used to compile:</p>
  
  <pre><code>g++ -ggdb `pkg-config --cflags opencv` -o main main.cpp `pkg-config --libs opencv` -lopencv_gpu 
  </code></pre>
  
  <p>And the error I get:</p>
  
  <pre><code>/usr/local/lib/libopencv_gpu.so: undefined reference to `cv::gpu::convertTo(cv::gpu::GpuMat const&amp;, cv::gpu::GpuMat&amp;, double, double, CUstream_st*)'
  /usr/local/lib/libopencv_gpu.so: undefined reference to `cv::gpu::setTo(cv::gpu::GpuMat&amp;, cv::Scalar_&lt;double&gt;, cv::gpu::GpuMat const&amp;, CUstream_st*)'
  /usr/local/lib/libopencv_gpu.so: undefined reference to `cv::gpu::setTo(cv::gpu::GpuMat&amp;, cv::Scalar_&lt;double&gt;, CUstream_st*)'
  collect2: error: ld returned 1 exit status
  </code></pre>
  
  <p>When I try to compile without the -lopencv_gpu option I get errors like:</p>
  
  <pre><code>main.cpp:61: undefined reference to `cv::gpu::threshold(cv::gpu::GpuMat const&amp;, cv::gpu::GpuMat&amp;, double, double, int, cv::gpu::Stream&amp;)'
  </code></pre>
  
  <p>Any ideas what might be wrong?</p>
  
  <p>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 <code>sudo make install.</code> I thought it would overwrite what was previously installed, but maybe something went wrong there?</p>
  
  <p>Running on Fedora 20, with Nvidia card.</p>