I am trying to build a C++ project with OpenCV 3.4.20 that's built with CUDA 11.6.2 on Visual Studio 2022 and on Windows 10. But, a few seconds after I begin to build the project, I see several errors such as this:
LNK2001 unresolved external symbol "int __cdecl cv::countNonZero(class cv::debug_build_guard::_InputArray const &)" (?countNonZero@cv@@YAHAEBV_InputArray@debug_build_guard@1@@Z)
System Specifications:
Windows 10
Visual Studio 2022
OpenCV 3.4.20 (built with CUDA and opencv_contrib modules)
CUDA 11.6.2
System variables are such as these:
CUDA_PATH = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6
CUDA_PATH_V11.6 = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6
PATH = C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\lib
C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\lib\x64
C:\Users\RIT\opencv-3.4\build\bin\
C:\Users\RIT\opencv-3.4\build\lib\
Relevant lines from TheopenCVProject.vcxproj file:
Under PropertyGroup Label="Globals":
<CudaToolkitCustomDir>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6</CudaToolkitCustomDir>
Under ImportGroup Label="ExtensionSettings":
<Import Project="$(VCTargetsPath)\BuildCustomizations\CUDA 11.6.props" />
Under PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'":
<IncludePath>C:\Users\RIT\opencv-3.4\build\install\include;$(IncludePath)</IncludePath>
<LibraryPath>C:\Users\RIT\opencv-3.4\build\install\x64\vc17\lib;$(LibraryPath)</LibraryPath>
Under ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"
<AdditionalIncludeDirectories>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalDependencies>opencv_cudabgsegm3420.lib;npps.lib;nppial.lib;nppicc.lib;nppidei.lib;nppif.lib;nppig.lib;nppim.lib;nppist.lib;nppisu.lib;nppitc.lib;nppc.lib;Gdiplus.lib;opencv_bgsegm3420.lib;opencv_videoio3420.lib;opencv_cudalegacy3420.lib;opencv_video3420.lib;opencv_core3420.lib;opencv_highgui3420.lib;cudart.lib;kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;cublas.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalLibraryDirectories>C:\Users\RIT\opencv-3.4\build\install\x64\vc17\lib;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\lib\x64;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
Under CudaCompile:
<CodeGeneration>compute_86,sm_86</CodeGeneration>
<AdditionalLibraryDirectories>C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\lib\x64;C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin\crt;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
Notes:
RIT
is the folder in which opencv, opencv_contrib and the folder of the project I want to build is located. The other one RİT
is the default one with all the directories you might expect from a regular User directory such as AppData, Documents and Downloads are located.I realized that, the project actually needs both Release and Debug libraries for Release build. So, I have followed these steps:
I have opened TheopenCVProject.sln
file with Visual Studio.
From the top bar of VS, I have selected Project
.
Then, I have clicked on Properties
from dropdown menu under Project
.
From properties window, I have selected Linker
.
In Linker
section, I have edited the list of Link Library Dependencies
.
I have added libraries of methods mentioned in errors to the list of Link Library Dependencies
.
Let's say we got this error: LNK2001 unresolved external symbol "int __cdecl cv::countNonZero(class cv::debug_build_guard::_InputArray const &)" (?countNonZero@cv@@YAHAEBV_InputArray@debug_build_guard@1@@Z)
and we use 3.4.20 version of OpenCV.
According to documentation of OpenCV countNonZero method is declared
in Core.hpp
, so we should add opencv_core3420d.lib
to the list of Link Library Dependencies
.