opencv-4.1 tries to link to missing functions of CUDA Toolkit-10.1 libraries.

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:
https://github.com/opencv/opencv/issues/14999

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.

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 …