I got stuck in building opencv-4.1 because of linking issue to CUDA Toolkit-10.1 libraries.
There are four missing functions:
cuCtxPushCurrent_v2
cuCtxPopCurrent_v2
cuCtxGetCurrent
cuCtxSynchronize
nvidiaOpticalFlow.obj : error LNK2019: unresolved external symbol cuCtxPushCurrent_v2 referenced in function "public: virtual void __cdecl `anonymous namespace'::NvidiaOpticalFlowImpl::calc(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputOutputArray const &,class cv::cuda::Stream &,class cv::_InputArray const &,class cv::_OutputArray const &)" (?calc@NvidiaOpticalFlowImpl@?A0xd838aad3@@UEAAXAEBV_InputArray@cv@@0AEBV_InputOutputArray@4@AEAVStream@cuda@4@0AEBV_OutputArray@4@@Z)
16> nvidiaOpticalFlow.obj : error LNK2019: unresolved external symbol cuCtxPopCurrent_v2 referenced in function "public: virtual void __cdecl `anonymous namespace'::NvidiaOpticalFlowImpl::calc(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputOutputArray const &,class cv::cuda::Stream &,class cv::_InputArray const &,class cv::_OutputArray const &)" (?calc@NvidiaOpticalFlowImpl@?A0xd838aad3@@UEAAXAEBV_InputArray@cv@@0AEBV_InputOutputArray@4@AEAVStream@cuda@4@0AEBV_OutputArray@4@@Z)
16> nvidiaOpticalFlow.obj : error LNK2019: unresolved external symbol cuCtxGetCurrent referenced in function "public: __cdecl `anonymous namespace'::NvidiaOpticalFlowImpl::NvidiaOpticalFlowImpl(int,int,enum _NV_OF_PERF_LEVEL,bool,bool,bool,int)" (??0NvidiaOpticalFlowImpl@?A0xd838aad3@@QEAA@HHW4_NV_OF_PERF_LEVEL@@_N11H@Z)
16> nvidiaOpticalFlow.obj : error LNK2019: unresolved external symbol cuCtxSynchronize referenced in function "public: virtual void __cdecl `anonymous namespace'::NvidiaOpticalFlowImpl::calc(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputOutputArray const &,class cv::cuda::Stream &,class cv::_InputArray const &,class cv::_OutputArray const &)" (?calc@NvidiaOpticalFlowImpl@?A0xd838aad3@@UEAAXAEBV_InputArray@cv@@0AEBV_InputOutputArray@4@AEAVStream@cuda@4@0AEBV_OutputArray@4@@Z)
16> D:\vcpkg\buildtrees\opencv\build\bin\Release\opencv_cudaoptflow410.dll : fatal error LNK1120: 4 unresolved externals
I am not sure if this is a bug of CUDA Toolkit or opencv. I hope to have a solution.
The issues is reported here:
opened 08:22AM - 09 Jul 19 UTC
closed 03:16AM - 10 Jul 19 UTC
category: build/install
category: gpu/cuda (contrib)
##### System information (version)
- OpenCV => 4.1.9
- Operating System / Plat… form => Windows 64 Bit
- Compiler => Visual Studio 2019
- CUDA Toolkit => 10.1
##### Detailed description
This is the output generated from cmake-gui
First I generate opencv solution for building by cmake-gui
```
_General configuration for OpenCV 4.1.0 =====================================
Version control: 327494e9-dirty
Platform:
Timestamp: 2019-07-08T15:05:05Z
Host: Windows 10.0.18362 AMD64
CMake: 3.14.1
CMake generator: Visual Studio 16 2019
CMake build tool: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/MSBuild/Current/Bin/MSBuild.exe
MSVC: 1921
CPU/HW features:
Baseline: SSE SSE2 SSE3
requested: SSE3
Dispatched code generation: AVX2
AVX2 (33 files): + SSSE3 SSE4_1 POPCNT SSE4_2 FP16 FMA3 AVX AVX2
C/C++:
Built as dynamic libs?: YES
C++ Compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.21.27702/bin/Hostx64/x64/cl.exe (ver 19.21.27702.2)
Extra dependencies: cudart_static.lib nppc.lib nppial.lib nppicc.lib nppicom.lib nppidei.lib nppif.lib nppig.lib nppim.lib nppist.lib nppisu.lib nppitc.lib npps.lib cublas.lib cufft.lib -LIBPATH:C:/Program Files/NVIDIA GPU Computing Toolkit/CUDA/v10.1/lib/x64
3rdparty dependencies:
OpenCV modules:
To be built: bgsegm bioinspired calib3d core cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudaobjdetect cudaoptflow cudastereo cudawarping cudev datasets dnn dnn_objdetect features2d flann gapi highgui img_hash imgcodecs imgproc line_descriptor ml objdetect optflow photo plot quality reg stitching superres surface_matching tracking ts video videoio videostab ximgproc
Disabled: aruco ccalib cudalegacy dpm face fuzzy hfs java_bindings_generator phase_unwrapping python_bindings_generator rgbd saliency shape stereo structured_light text world xfeatures2d xobjdetect xphoto
Disabled by dependency: -
Unavailable: cnn_3dobj cvv freetype hdf java js matlab ovis python2 python3 sfm vi_z
```
Next, I opened and built the library, after approx one hour I got almost dlls built successfully except this one: "cudaoptflow" failed linking with errors:
```
error LNK2019: unresolved external symbol cuCtxPushCurrent_v2 referenced in function "public: virtual void __cdecl `anonymous namespace'::NvidiaOpticalFlowImpl::calc(
//other similar errors with functions
cuCtxPopCurrent_v2
cuCtxGetCurrent
cuCtxSynchronize
```
I doubt that maybe those functions above have been deprecated or I configured something wrong.
I want to know if there is someone else gets similar error and if there is a solution for this issue.
##### Steps to reproduce
Just install CUDA Toolkit, run cmake-gui then set path for extra-modules (contrib) and select cudaoptflow module, then build the generated solution.
The comment that you were given on your issue explains the problem.
You are not linking against the CUDA driver API, i.e. the “cuda” library, and apparently the optical flow routines require that.
Thanks for your comment.
The issue was fixed in opencv-4.1.1-pre. The required lib is “Computing Toolkit\CUDA\v10.1\lib\x64\cuda.lib”
I am confused that why you mentioned “CUDA driver API” instead of CUDA Toolkit.
1 Like
The cuda driver API is implemented in the cuda.lib library. It is like saying cuda.lib in this context.
functions like cuCtxPopCurrent_v2 belong to the CUDA driver API
OpenCV 4.X links to CUDA Driver API again (in OpenCV 3.X the dependency to driver API got removed after I brought up the issue) ? Makes deploying application on machines without NVIDIA GPU really problematic, even if the application never uses the optical flow routines …