编译环境 ubuntu1604+opencv3.2+cuda8.0
编译opencv时碰到如下是错误
Scanning dependencies of target example_gpu_alpha_comp
CMakeFiles/example_gpu_driver_api_multi.dir/driver_api_multi.cpp.o: In function `destroyContexts()':
driver_api_multi.cpp:(.text._Z15destroyContextsv+0xc): undefined reference to `cuCtxDestroy_v2'
driver_api_multi.cpp:(.text._Z15destroyContextsv+0x1c): undefined reference to `cuCtxDestroy_v2'
CMakeFiles/example_gpu_driver_api_multi.dir/driver_api_multi.cpp.o: In function `Worker::operator()(int) const':
driver_api_multi.cpp:(.text._ZNK6WorkerclEi+0x37): undefined reference to `cuCtxPushCurrent_v2'
driver_api_multi.cpp:(.text._ZNK6WorkerclEi+0x893): undefined reference to `cuCtxPopCurrent_v2'
CMakeFiles/example_gpu_driver_api_multi.dir/driver_api_multi.cpp.o: In function `main':
driver_api_multi.cpp:(.text.startup.main+0x11c): undefined reference to `cuInit'
driver_api_multi.cpp:(.text.startup.main+0x133): undefined reference to `cuDeviceGet'
driver_api_multi.cpp:(.text.startup.main+0x14d): undefined reference to `cuCtxCreate_v2'
driver_api_multi.cpp:(.text.startup.main+0x15d): undefined reference to `cuCtxPopCurrent_v2'
driver_api_multi.cpp:(.text.startup.main+0x172): undefined reference to `cuDeviceGet'
driver_api_multi.cpp:(.text.startup.main+0x18c): undefined reference to `cuCtxCreate_v2'
driver_api_multi.cpp:(.text.startup.main+0x19c): undefined reference to `cuCtxPopCurrent_v2'
collect2: error: ld returned 1 exit status
samples/gpu/CMakeFiles/example_gpu_driver_api_multi.dir/build.make:125: recipe for target 'bin/example_gpu_driver_api_multi' failed
make[2]: *** [bin/example_gpu_driver_api_multi] Error 1
CMakeFiles/Makefile2:39358: recipe for target 'samples/gpu/CMakeFiles/example_gpu_driver_api_multi.dir/all' failed
make[1]: *** [samples/gpu/CMakeFiles/example_gpu_driver_api_multi.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
cmake命令参数如下
cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/usr/local -D INSTALL_C_EXAMPLES=ON -D INSTALL_PYTHON_EXAMPLES=ON -D WITH_TBB=ON -D WITH_V4L=ON -D WITH_QT=ON -D WITH_OPENGL=ON -D OPENCV_EXTRA_MODULES_PATH=../../opencv_contrib/modules -D BUILD_EXAMPLES=ON -D CMAKE_LIBRARY_PATH=/usr/local/cuda-8.0/lib64/stubs -D CUDA_CUDA_LIBRARY=/usr/local/cuda-8.0/lib64/stubs/libcuda.so ..
原因是找不到cuda库,解决方式如下(红色为新添加)
https://github.com/opencv/opencv/pull/10954/commits/5c66ce7f29976bc6307b5a7191f040fa7337e437
https://github.com/opencv/opencv/pull/10954/files
3 samples/gpu/CMakeLists.txt
@@ -50,6 +50,9 @@ endif()
foreach(sample_filename ${all_samples})
ocv_define_sample(tgt ${sample_filename} gpu)
ocv_target_link_libraries(${tgt} ${OPENCV_LINKER_LIBS} ${OPENCV_CUDA_SAMPLES_REQUIRED_DEPS})
if(HAVE_CUDA AND NOT ANDROID)
ocv_target_link_libraries(${tgt} ${CUDA_CUDA_LIBRARY})
endif()
if(HAVE_opencv_xfeatures2d)
ocv_target_link_libraries(${tgt} opencv_xfeatures2d)
endif()