title: Building OpenCV 3.1 on Ubuntu 16.04 fails (undefined references)
body: <p>I am trying to install OpenCV3.1 on my Ubuntu 16.04 for development in QT5. Sadly, building it from source always errors out due to undefined references (see below). </p>
  
  <p>I used the following:</p>
  
  <pre><code>cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D BUILD_TIFF=ON -D WITH_VTK=ON..
  </code></pre>
  
  <p>And it works fine. But building it always produces this error</p>
  
  <pre><code>../../lib/libopencv_viz.so.3.1.0: undefined reference to `vtkSTLReader::New()'
  ../../lib/libopencv_viz.so.3.1.0: undefined reference to `vtkOBJReader::New()'
  collect2: error: ld returned 1 exit status
  modules/viz/CMakeFiles/opencv_test_viz.dir/build.make:232: recipe for target 'bin/opencv_test_viz' failed
  make[2]: *** [bin/opencv_test_viz] Error 1
  CMakeFiles/Makefile2:3358: recipe for target 'modules/viz/CMakeFiles/opencv_test_viz.dir/all' failed
  make[1]: *** [modules/viz/CMakeFiles/opencv_test_viz.dir/all] Error 2
  make[1]: *** Waiting for unfinished jobs....
  </code></pre>
  
  <p>Of course I googled and tried everything I found. Tried several different cmake flags (or rather, without any), tried reinstalling libvtk5-dev and also tried libvtk6-dev and even build vtk7.1 from source, since I am assuming something is missing from there. </p>
  
  <p>I also tried adding the opencv_contrib via</p>
  
  <pre><code>cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_FFMPEG=ON -D WITH_OPENGL=ON -D BUILD_TIFF=ON -D WITH_VTK=ON -D BUILD_EXAMPLES=ON -D OPENCV_EXTRA_MODULES_PATH=/home/user/opencv/opencv-3.1.0/opencv_contrib/modules ..
  </code></pre>
  
  <p>But that already produced the following error</p>
  
  <pre><code>CMake Error at opencv_contrib/modules/text/CMakeLists.txt:22 (ocv_add_testdata): `Unknown CMake command "ocv_add_testdata".
  </code></pre>
  
  <p>Also please note that I did upgrade/update all the packages that are listed <a href="http://rodrigoberriel.com/2014/10/installing-opencv-3-0-0-on-ubuntu-14-04/" rel="nofollow noreferrer">here</a> and <a href="http://docs.opencv.org/trunk/d7/d9f/tutorial_linux_install.html" rel="nofollow noreferrer">here</a> </p>
  
  <p>So basically after two days randomly trying all the possible solutions I could find via google, I am now asking here. 
  Hopefully someone knows how to fix this, thank you!</p>
  
  <p>Edit: I only get these problems with OpenCV3.1. I do have a working OpenCV 2.4.13</p>