Sample build failed with CUDA 5.5 and OpenCV 2.4.6.1
I am trying to use ubuntu 12.04 x64 with CUDA 5.5 Production Release to build OpenCV 2.4.6.1
I can build without sample correctly but when I choose to build sample it will failed with
Linking CXX executable ../../bin/gpu-example-driver_api_stereo_multi
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+0x19): undefined reference to `cuCtxPushCurrent_v2'
driver_api_multi.cpp:(.text._ZNK6WorkerclEi+0x6bf): 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+0x94): undefined reference to `cuInit'
driver_api_multi.cpp:(.text.startup.main+0xb1): undefined reference to `cuDeviceGet'
driver_api_multi.cpp:(.text.startup.main+0xd2): undefined reference to `cuCtxCreate_v2'
driver_api_multi.cpp:(.text.startup.main+0xed): undefined reference to `cuCtxPopCurrent_v2'
driver_api_multi.cpp:(.text.startup.main+0x10d): undefined reference to `cuDeviceGet'
driver_api_multi.cpp:(.text.startup.main+0x12e): undefined reference to `cuCtxCreate_v2'
driver_api_multi.cpp:(.text.startup.main+0x149): undefined reference to `cuCtxPopCurrent_v2'
collect2: ld returned 1 exit status
make[2]: *** [bin/gpu-example-driver_api_multi] Error 1
make[1]: *** [samples/gpu/CMakeFiles/example_gpu_driver_api_multi.dir/all] Error 2
make[1]: *** Waiting for unfinished jobs....
CMakeFiles/example_gpu_driver_api_stereo_multi.dir/driver_api_stereo_multi.cpp.o: In function `destroyContexts()':
driver_api_stereo_multi.cpp:(.text._Z15destroyContextsv+0xc): undefined reference to `cuCtxDestroy_v2'
driver_api_stereo_multi.cpp:(.text._Z15destroyContextsv+0x1c): undefined reference to `cuCtxDestroy_v2'
CMakeFiles/example_gpu_driver_api_stereo_multi.dir/driver_api_stereo_multi.cpp.o: In function `contextOff()':
driver_api_stereo_multi.cpp:(.text._Z10contextOffv[contextOff()]+0xa): undefined reference to `cuCtxPopCurrent_v2'
CMakeFiles/example_gpu_driver_api_stereo_multi.dir/driver_api_stereo_multi.cpp.o: In function `contextOn(int)':
driver_api_stereo_multi.cpp:(.text._Z9contextOni[contextOn(int)]+0x10): undefined reference to `cuCtxPushCurrent_v2'
CMakeFiles/example_gpu_driver_api_stereo_multi.dir/driver_api_stereo_multi.cpp.o: In function `Worker::operator()(int) const':
driver_api_stereo_multi.cpp:(.text._ZNK6WorkerclEi+0x14): undefined reference to `cuCtxPushCurrent_v2'
driver_api_stereo_multi.cpp:(.text._ZNK6WorkerclEi+0x106): undefined reference to `cuCtxPopCurrent_v2'
CMakeFiles/example_gpu_driver_api_stereo_multi.dir/driver_api_stereo_multi.cpp.o: In function `main':
driver_api_stereo_multi.cpp:(.text.startup.main+0x80b): undefined reference to `cuInit'
driver_api_stereo_multi.cpp:(.text.startup.main+0x822): undefined reference to `cuDeviceGet'
driver_api_stereo_multi.cpp:(.text.startup.main+0x83d): undefined reference to `cuCtxCreate_v2'
driver_api_stereo_multi.cpp:(.text.startup.main+0x85c): undefined reference to `cuDeviceGet'
driver_api_stereo_multi.cpp:(.text.startup.main+0x877): undefined reference to `cuCtxCreate_v2'
collect2: ld returned 1 exit status
It seems like forgetting link libcudart, I think this can be fixed by modifying CMakeLists.txt but I don't know how to fix it.
The driver API examples are CUDA based examples using the specific NVIDIA GPU API. It is possible that these need extra functionality from NVIDIA itself or that you haven't got a card that can use this functionality.
Do the other examples build correctly?
No, when make detect error it will just leave... Is there a way to build sample only?
Yes, include the sample file in a empty project, add all linker dependencies, then build it yourself.
I choose another way, I comment "add_subdirectory(gpu)" in "opencv-2.4.6.1/samples/CMakeLists.txt" than it can be build successfully
I add "-L/usr/local/cuda/lib64 -lcuda" to "opencv-2.4.6.1/build/samples/gpu/CMakeFiles/example_gpu_driver_api_multi.dir/link.txt" and it can be build correct, but next target gpu-example-driver_api_stereo_multi will still failed. I think there should be a way to modify CMakeLists.txt to add this to every target, but I have no idea about cmake
Please make a bug report about this and about your solution at the bug report section. Developers will try to find a solution for it then.
Thanks, I've reported it