# How do I fix an undefined reference error while build opencv from source?

I'm building opencv 3.2 from source on Ubuntu 16.04 using these instructions: http://docs.opencv.org/trunk/d7/d9f/t...

After running make -j7 when I get to 98% I get this error:

[ 98%] Built target opencv_cudaoptflow
Makefile:160: recipe for target 'all' failed
make: *** [all] Error 2


If I scroll up in the console I see that there were problems earlier

[ 96%] Linking CXX executable ../../bin/opencv_test_cudalegacy
../../lib/libopencv_cudalegacy.so.3.2.0: undefined reference to nppiGraphcut_32s8u'
../../lib/libopencv_cudalegacy.so.3.2.0: undefined reference to nppiGraphcutInitAlloc'
../../lib/libopencv_cudalegacy.so.3.2.0: undefined reference to nppiGraphcutFree'
../../lib/libopencv_cudalegacy.so.3.2.0: undefined reference to nppiGraphcut8_32s8u'
../../lib/libopencv_cudalegacy.so.3.2.0: undefined reference to nppiGraphcutGetSize'
../../lib/libopencv_cudalegacy.so.3.2.0: undefined reference to nppiGraphcut8GetSize'
../../lib/libopencv_cudalegacy.so.3.2.0: undefined reference to nppiGraphcut8InitAlloc'
../../lib/libopencv_cudalegacy.so.3.2.0: undefined reference to nppiGraphcut_32f8u'
../../lib/libopencv_cudalegacy.so.3.2.0: undefined reference to nppiGraphcut8_32f8u'
collect2: error: ld returned 1 exit status
modules/cudalegacy/CMakeFiles/opencv_test_cudalegacy.dir/build.make:501: recipe for target 'bin/opencv_test_cudalegacy' failed
make[2]: *** [bin/opencv_test_cudalegacy] Error 1
CMakeFiles/Makefile2:8465: recipe for target 'modules/cudalegacy/CMakeFiles/opencv_test_cudalegacy.dir/all' failed
make[1]: *** [modules/cudalegacy/CMakeFiles/opencv_test_cudalegacy.dir/all] Error 2


It looks like it's not recognizing any of the nppiGraphcut functions in cudalegacy. Does anyone know how to fix this?

My cmake options were cmake -D CMAKE_BUILD_TYPE=Release -D CMAKE_INSTALL_PREFIX=/usr/local -DBUILD_LIBPROTOBUF_FROM_SOURCES=ON .. I've tried with an without the -DBUILD_LIBPROTOBUF_FROM_SOURCES=ON.

I know it's recognizing that I have CUDA installed because I get this output in the beginning

-- CUDA detected: 7.5
-- CUDA NVCC target flags: -gencode;arch=compute_20,code=sm_20;-gencode;arch=compute_30,code=sm_30;-gencode;arch=compute_35,code=sm_35;-gencode;arch=compute_37,code=sm_37;-gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_52,code=sm_52;-D_FORCE_INLINES
`

I don't know what else to try, I cant find anything on this error when googling it. Let me know if I need to post more information.