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

asked 2017-03-19 15:36:18 -0600

mddrill gravatar image

updated 2017-03-20 02:15:29 -0600

berak gravatar image

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.

Thank you for your help!

edit retag flag offensive close merge delete

Comments

I can only give you a hint because I haven't looked at the CMake files. This is a linking error. The compiler will first compile all of your source code; when it's doing this it will use the header files (defined by the #include lines) to determine the functions available to a given source file. Any references to functions described in header files will then be left as empty pointers which the compiler will fill in during the linking stage of compilation (usually one of the last stages). This is why you see the error happen at the end.

The compiler is saying that there are functions in "../../lib/libopencv_cudalegacy.so.3.2.0" that have not yet been filled in.

So, somewhere in the CMake files there is a reference for building "../../bin/opencv_test_cudalegacy" which needs to be linked.

cpagravel gravatar imagecpagravel ( 2017-03-20 12:34:02 -0600 )edit