"LNK2001 unresolved symbol" Erros about "cv::" Classes and Methods When Building a C++ Project with OpenCV and CUDA #25599
Labels
category: build/install
question (invalid tracker)
ask questions and other "no action" items here: https://forum.opencv.org
System Information
System Specifications:
Windows 10
Visual Studio 2022 (v143)
MSVC 14
C++14
CMake 3.29.3
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
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>
Detailed description
When trying to build a C++project on Release mode and for x64, I see more than 20 errors like the following:
Notes:
RIT
is the folder in which opencv, opencv_contrib and the folder of the project I want to build is located. The other oneRİ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.Steps to reproduce
Install Visual Studio 2022 and install ".NET desktop development", "Desktop development with C++" and "Universal Windows Platform development" workloads.
Install CUDA 11.6.2 without NSight VSE, NSight Systems, NSight Compute and NSight NVTX.
Install CMake 3.29.3 and add it to the path for all users while installing.
Make sure that "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\bin", "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\lib" and "C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.6\lib\x64" are added the the PATH system variable.
Download zips for opencv and opencv_contrib from "https://github.com/opencv/opencv/archive/refs/heads/3.4.zip" and "https://github.com/opencv/opencv_contrib/archive/refs/heads/3.4.zip". Then, extract both zip files under the same directory.
Open CMake GUI. Write the directory where opencv is extracted to "Where is the source code:" and then, write "/build" to "Where to build the binaries".
Press configure.
Select "Visual Studio 17 2022" for "Specify the generator for this project" and leave other fields blank. Then click "Finish"
After the configuration, unselect "BUILD_PROTOBUF", "BUILD_JAVA" and "WITH_PROTOBUF". Then, select "WITH_CUDA". Then, enter "/modules" to "OPENCV_EXTRA_MODULES_PATH".
Open FindCUDA.cmake at "<where oğencv is extracted to>/cmake" with a notepad.
Delete the line reads
find_cuda_helper(nppi)
underif(CUDA_VERSION_GREATER "7.5")
and write the following to it's placeStill inside FindCUDA.cmake, find the line starts with
set(CUDA_nppi_LIBRARY
and delete${CUDA_nppi_LIBRARY};
and write${CUDA_nppial_LIBRARY};${CUDA_nppicc_LIBRARY};${CUDA_nppicom_LIBRARY};${CUDA_nppidei_LIBRARY};${CUDA_nppif_LIBRARY};${CUDA_nppig_LIBRARY};${CUDA_nppim_LIBRARY};${CUDA_nppist_LIBRARY};${CUDA_nppisu_LIBRARY};${CUDA_nppitc_LIBRARY};
in it's place.Save and close the FindCUDA.cmake file.
Back in CMake GUI, click on "Generate"
After the generation is successfull, go to "/build". Then, find and open OpenCV.sln file with Vision Studio 2022.
Select build mode as Release and build platform as x64
From projct explorer, find "ALL_BUILD". Then, right-click on "ALL_BUILD". Then, select "Compile".
After build is successfull. Do the same to "INSTALL" which is just under "ALL_BUILD".
After that build is also successfull, close the visual studio. Then create a c++ project with c++ (.cpp) and CUDA (.cu) code.
use
cv::countNonZero()
,cv::merge
andcv::cvtColor
methods on CUDA (.cu) code and usecv::cvtColor
,cvSaveImage
,cv::Mat::setTo
andcv::imwrite
methods in C++ code.Then, save and close the project and Visual Studio.
Find and open .vcxproj file with notepad. Then, edit necessary lines referring to the lines from TheopenCVProject.vcxproj file. Which I have provided under "System Specifications" section.
Save and close the file. Then, find and open OpenCV.sln file with Vision Studio 2022.
Make sure that build mode is release and build platform is x64.
Build the project.
After a while (less than a minute) see that there are several "LNK2001 unresolved external symbol" errors about methods and classes beginning with "cv::". Also obseve that all the errors have "debug_build_guard" and a strange mixture of "@" symbol and seemingly random letters like: "
@N@1@AEBV
".Issue submission checklist
The text was updated successfully, but these errors were encountered: