title: Building OpenCV 3.1 with CUDA fails
body: <p>I am following the instructions of <a href="http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/" rel="nofollow">http://www.pyimagesearch.com/2015/07/20/install-opencv-3-0-and-python-3-4-on-ubuntu/</a> to build OpenCV.</p>
  
  <p>Versions on my system: OpenCV 3.1, Python 3.5. Running Ubuntu 16.04.1</p>
  
  <p>Also, I have CUDA 8.0RC installed on my system, which is detected when running cmake.</p>
  
  <p>As CUDA doesn't seem to support gcc-5 or newer, I installed gcc 4.7 as well, and passed it to my cmake call with the <code>CUDA_NVCC_FLAGS</code> flag:</p>
  
  <pre><code>cmake -D CMAKE_BUILD_TYPE=RELEASE \
      -D CMAKE_INSTALL_PREFIX=/usr/local \
      -D INSTALL_C_EXAMPLES=OFF \
      -D INSTALL_PYTHON_EXAMPLES=ON \
      -D CUDA_NVCC_FLAGS="-ccbin gcc-4.7" \
      -D OPENCV_EXTRA_MODULES_PATH=~/opencv_contrib/modules \
      -D BUILD_EXAMPLES=ON ..
  </code></pre>
  
  <p>cmake completes successfully. I then try to call <code>make -j4</code>, which runs for a while, but fails at 44%, with the following message that doesn't help me at all:</p>
  
  <pre><code>[ 44%] Linking CXX shared library ../../lib/libopencv_cudaimgproc.so
  [ 44%] Built target opencv_cudaimgproc
  Makefile:160: recipe for target 'all' failed
  make: *** [all] Error 2
  </code></pre>
  
  <p>What is happening here? I have no idea how cmake or make actually work internally and am getting increasingly frustrated. I was able to fix several issues before, but this one confuses me. I simply want OpenCV to run in my python3 installation...</p>
  
  <hr>
  
  <p><strong>EDIT</strong>: Running <code>make VERBOSE=1 -j4</code> shows the following additional output:</p>
  
  <pre><code>[ 47%] Linking CXX shared library ../../lib/libopencv_photo.so
  cd /home/flo/tmp/opencv/OpenCV1/build/modules/photo &amp;&amp; /usr/bin/cmake -E cmake_link_script CMakeFiles/opencv_photo.dir/link.txt --verbose=1
  /usr/bin/c++  -fPIC    -fsigned-char -W -Wall -Werror=return-type -Werror=non-virtual-dtor -Werror=address -Werror=sequence-point -Wformat -Werror=format-security   -Winit-self -Wpointer-arith -Wshadow -Wsign-promo -Wno-narrowing -Wno-delete-non-virtual-dtor -fdiagnostics-show-option -Wno-long-long -pthread -fomit-frame-pointer -msse -msse2 -mno-avx -msse3 -mno-ssse3 -mno-sse4.1 -mno-sse4.2 -ffunction-sections -fvisibility=hidden -fvisibility-inlines-hidden -Wno-undef -Wno-missing-declarations -O3 -DNDEBUG  -DNDEBUG  -shared -Wl,-soname,libopencv_photo.so.3.1 -o ../../lib/libopencv_photo.so.3.1.0 CMakeFiles/opencv_photo.dir/src/contrast_preserve.cpp.o CMakeFiles/opencv_photo.dir/src/seamless_cloning_impl.cpp.o CMakeFiles/opencv_photo.dir/src/merge.cpp.o CMakeFiles/opencv_photo.dir/src/npr.cpp.o CMakeFiles/opencv_photo.dir/src/seamless_cloning.cpp.o CMakeFiles/opencv_photo.dir/src/align.cpp.o CMakeFiles/opencv_photo.dir/src/denoise_tvl1.cpp.o CMakeFiles/opencv_photo.dir/src/calibrate.cpp.o CMakeFiles/opencv_photo.dir/src/denoising.cuda.cpp.o CMakeFiles/opencv_photo.dir/src/tonemap.cpp.o CMakeFiles/opencv_photo.dir/src/denoising.cpp.o CMakeFiles/opencv_photo.dir/opencl_kernels_photo.cpp.o CMakeFiles/cuda_compile.dir/src/cuda/cuda_compile_generated_nlm.cu.o  -L/usr/local/cuda-8.0/lib64 ../../lib/libopencv_cudaimgproc.so.3.1.0 -ldl -lm -lpthread -lrt -lGLU -lGL -ltbb -latomic ../../../3rdparty/ippicv/unpack/ippicv_lnx/lib/intel64/libippicv.a -lcudart -lnppc -lnppi -lnpps -lcufft -L/usr/local/cuda-8.0/lib64 -lcudart -lnppc -lnppi -lnpps ../../lib/libopencv_cudafilters.so.3.1.0 ../../lib/libopencv_cudaarithm.so.3.1.0 ../../lib/libopencv_imgproc.so.3.1.0 ../../lib/libopencv_core.so.3.1.0 ../../lib/libopencv_cudev.so.3.1.0 -lcufft -Wl,-rpath,/usr/local/cuda-8.0/lib64:/home/flo/tmp/opencv/OpenCV1/build/lib:
  cd /home/flo/tmp/opencv/OpenCV1/build/modules/photo &amp;&amp; /usr/bin/cmake -E cmake_symlink_library ../../lib/libopencv_photo.so.3.1.0 ../../lib/libopencv_photo.so.3.1 ../../lib/libopencv_photo.so
  make[2]: Leaving directory '/home/flo/tmp/opencv/OpenCV1/build'
  [ 47%] Built target opencv_photo
  make[1]: Leaving directory '/home/flo/tmp/opencv/OpenCV1/build'
  Makefile:160: recipe for target 'all' failed
  make: *** [all] Error 2
  </code></pre>
  
  <hr>
  
  <p><strong>EDIT 2</strong> Following the suggestions from the comments, I tried a serial build with:</p>
  
  <p><code>make clean &amp;&amp; make VERBOSE=1</code></p>
  
  <p>Unfortunately it still fails, the end of the output looks like this:</p>
  
  <pre><code>// ... many warnings like this:
  tmpxft_0000479e_00000000-4_test_cvt.compute_35.cudafe1.cpp:(.text._ZN7testing8internal21TypeParameterizedTestI7CvtTestNS0_11TemplateSelI19CvtTest_GpuMat_TestEENS0_6Types5IhtsifEEE8RegisterEPKcSA_SA_i[_ZN7testing8internal21TypeParameterizedTestI7CvtTestNS0_11TemplateSelI19CvtTest_GpuMat_TestEENS0_6Types5IhtsifEEE8RegisterEPKcSA_SA_i]+0x46e): undefined reference to `testing::Message::GetString() const'
  tmpxft_0000479e_00000000-4_test_cvt.compute_35.cudafe1.cpp:(.text._ZN7testing8internal21TypeParameterizedTestI7CvtTestNS0_11TemplateSelI19CvtTest_GpuMat_TestEENS0_6Types5IhtsifEEE8RegisterEPKcSA_SA_i[_ZN7testing8internal21TypeParameterizedTestI7CvtTestNS0_11TemplateSelI19CvtTest_GpuMat_TestEENS0_6Types5IhtsifEEE8RegisterEPKcSA_SA_i]+0x787): undefined reference to `testing::Message::GetString() const'
  CMakeFiles/opencv_test_cudev.dir/opencv_test_cudev_generated_test_arithm_func.cu.o:tmpxft_000048b6_00000000-4_test_arithm_func.compute_35.cudafe1.cpp:(.text._ZN7testing8internal21TypeParameterizedTestI8SqrtTestNS0_11TemplateSelI20SqrtTest_GpuMat_TestEENS0_6Types1IfEEE8RegisterEPKcSA_SA_i[_ZN7testing8internal21TypeParameterizedTestI8SqrtTestNS0_11TemplateSelI20SqrtTest_GpuMat_TestEENS0_6Types1IfEEE8RegisterEPKcSA_SA_i]+0x14b): more undefined references to `testing::Message::GetString() const' follow
  
  collect2: error: ld returned 1 exit status
  make[2]: *** [bin/opencv_test_cudev] Error 1
  make[1]: *** [modules/cudev/test/CMakeFiles/opencv_test_cudev.dir/all] Error 2
  make: *** [all] Error 2
  </code></pre>