# I get "Unresolved external symbol" error when trying to build a C++ project with OpenCV and CUDA

**URL:** <https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662>\
**Category:** C++\
**Tags:** windows, build, cuda\
**Created:** [May 16, 2024, 1:36pm UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662 "2024-05-16T13:36:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![mericgeren](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mericgeren](https://forum.opencv.org/u/mericgeren)\
**Post date:** [May 16, 2024, 1:36pm UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/1 "2024-05-16T13:36:23Z")

</div>

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:

- Relevant lines from TheopenCVProject.vcxproj file:

**Notes:**

1. There are two folders under Users except Default and Public: `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.
2. When I check opencv folders I can see that all needed libraries are there and I can see that the functions subject of errors are both declared and defined in their respective .cpp, .h and .hpp files.
3. There are both release and debug libraries under the directory into which I have built the OpenCV.
4. Tried to build the project in debug mode, enabling debug information with /Z7 option and disabling optimization flags to no avail.
5. If I try to compile each .cu and .cpp file one by one, they all get built successfully.

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [May 16, 2024, 1:57pm UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/2 "2024-05-16T13:57:06Z")

</div>

> [@mericgeren](#):
>
> CUDA 11.6.2

[CUDA Toolkit 11.6.2](https://developer.nvidia.com/cuda-11-6-2-download-archive) (March 2022), [Versioned Online Documentation](https://docs.nvidia.com/cuda/archive/11.6.2/)

OpenCV – 3.4.0  
 ![](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/6/679338f1c01fb89131a64bc9c2b932b5e4adffa6.png)2017-12-23

Good luck

---

<div class="post-metadata">

**Author:** ![mericgeren](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mericgeren](https://forum.opencv.org/u/mericgeren)\
**Post date:** [May 16, 2024, 2:29pm UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/3 "2024-05-16T14:29:43Z")

</div>

Hi @laurent.berger

> [@mericgeren](#):
>
> OpenCV 3.4.20 (built with CUDA and opencv\_contrib modules)

Would you mind taking a look at [OpenCV 3.4.20 tag page](https://github.com/opencv/opencv/releases/tag/3.4.20) and [Opencv 3.4 branch head GitHub page](https://github.com/opencv/opencv/tree/3.4)?

OpenCV - 3.4.20  
 ![](https://us1.discourse-cdn.com/flex020/uploads/opencv/original/2X/6/679338f1c01fb89131a64bc9c2b932b5e4adffa6.png)2023-06-27

Thanks

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [May 16, 2024, 6:49pm UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/4 "2024-05-16T18:49:24Z")

</div>

Ok my mistake but why don’t you use old opencv version?

> [@mericgeren](#):
>
> `NonZero@cv@@YAHAEBV_Input`

Why don’t you use CMake to build VS project? [opencv/samples/cpp/example\_cmake at 4.x · opencv/opencv · GitHub](https://github.com/opencv/opencv/tree/4.x/samples/cpp/example_cmake)

---

<div class="post-metadata">

**Author:** ![mericgeren](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mericgeren](https://forum.opencv.org/u/mericgeren)\
**Post date:** [May 17, 2024, 6:59am UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/6 "2024-05-17T06:59:11Z")

</div>

> [@mericgeren](#):
>
> compute\_86,sm\_86

When I tried an older version (3.1.0), it proved incompatible with the system and the opencv itself failed to build.

> [@laurent.berger](#):
>
> Why don’t you use CMake to build VS project?

To have ease of control over how and to where I build

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [May 17, 2024, 7:11am UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/7 "2024-05-17T07:11:12Z")

</div>

> [@mericgeren](#):
>
> o have ease of control over how and to where I build

Use cmake and check difference with your own project.

---

<div class="post-metadata">

**Author:** ![mericgeren](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mericgeren](https://forum.opencv.org/u/mericgeren)\
**Post date:** [May 17, 2024, 12:23pm UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/8 "2024-05-17T12:23:19Z")

</div>

When I try to build with opencv I see several errors like the following:

```auto
LNK2019: unresolved external symbol nppiMulC_32f_C3IR referenced in function "enum cudaError __cdecl calcDev3C(float const *,int,int)" (?calcDev3C@@YA?AW4cudaError@@PEBMHH@Z)

```

**Notes:**

1. Checked properties for each CUDA (.cu) file and item type was CUDA C/C++ for all CUDA files. Also, there was an object files (.cu.obj) for each CUDA file.

2. Seeing “/MD” at Runtime library property under C/C++ section in properties of the .sln file.

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [May 17, 2024, 1:11pm UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/9 "2024-05-17T13:11:39Z")

</div>

> [@mericgeren](#):
>
> When I try to build with opencv I see several errors like the following:

> [@mericgeren](#):
>
> I am trying to build a C++ project with OpenCV 3.4.20

Have you got problem to build opencv or your own project?

---

<div class="post-metadata">

**Author:** ![mericgeren](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mericgeren](https://forum.opencv.org/u/mericgeren)\
**Post date:** [May 17, 2024, 1:25pm UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/10 "2024-05-17T13:25:18Z")

</div>

I have got problem to build my own project

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [May 17, 2024, 1:29pm UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/11 "2024-05-17T13:29:27Z")

</div>

using opencv 5 I have all those libs in my VS project

C:\install\opencv\x64\vc17\lib\opencv\_gapi500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_stitching500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_alphamat500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_bgsegm500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_bioinspired500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_ccalib500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudabgsegm500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudafeatures2d500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudaobjdetect500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudastereo500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_dnn\_objdetect500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_dnn\_superres500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_dnnlegacy500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_dpm500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_face500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_fuzzy500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_hfs500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_img\_hash500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_intensity\_transform500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_line\_descriptor500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_mcc500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_my\_module500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_quality500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_rapid500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_reg500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_rgbd500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_saliency500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_sfm500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_signal500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_structured\_light500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_superres500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_surface\_matching500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_videostab500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_viz500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_wechat\_qrcode500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_xfeatures2d500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_xphoto500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_xstereo500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_shape500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_phase\_unwrapping500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudacodec500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudaoptflow500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudalegacy500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_calib500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudawarping500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_optflow500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_ximgproc500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_xobjdetect500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_objdetect500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_photo500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudaimgproc500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudafilters500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudaarithm500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_stereo500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_tracking500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_highgui500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_video500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_3d500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_videoio500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_datasets500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_imgcodecs500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_plot500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_text500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_dnn500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_features2d500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_flann500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_imgproc500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_ml500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_core500.lib  
C:\install\opencv\x64\vc17\lib\opencv\_cudev500.lib

---

<div class="post-metadata">

**Author:** ![mericgeren](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mericgeren](https://forum.opencv.org/u/mericgeren)\
**Post date:** [May 20, 2024, 6:52am UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/12 "2024-05-20T06:52:51Z")

</div>

I have these libs at C:\Users\RIT\opencv-3.4\build\install\x64\vc17\lib (Without Java, Python and Protobuf)

opencv\_aruco3420.lib  
opencv\_aruco3420d.lib  
opencv\_bgsegm3420.lib  
opencv\_bgsegm3420d.lib  
opencv\_bioinspired3420.lib  
opencv\_bioinspired3420d.lib  
opencv\_calib3d3420.lib  
opencv\_calib3d3420d.lib  
opencv\_ccalib3420.lib  
opencv\_ccalib3420d.lib  
opencv\_core3420.lib  
opencv\_core3420d.lib  
opencv\_cudaarithm3420.lib  
opencv\_cudaarithm3420d.lib  
opencv\_cudabgsegm3420.lib  
opencv\_cudabgsegm3420d.lib  
opencv\_cudacodec3420.lib  
opencv\_cudacodec3420d.lib  
opencv\_cudafeatures2d3420.lib  
opencv\_cudafeatures2d3420d.lib  
opencv\_cudafilters3420.lib  
opencv\_cudafilters3420d.lib  
opencv\_cudaimgproc3420.lib  
opencv\_cudaimgproc3420d.lib  
opencv\_cudalegacy3420.lib  
opencv\_cudalegacy3420d.lib  
opencv\_cudaobjdetect3420.lib  
opencv\_cudaobjdetect3420d.lib  
opencv\_cudaoptflow3420.lib  
opencv\_cudaoptflow3420d.lib  
opencv\_cudastereo3420.lib  
opencv\_cudastereo3420d.lib  
opencv\_cudawarping3420.lib  
opencv\_cudawarping3420d.lib  
opencv\_cudev3420.lib  
opencv\_cudev3420d.lib  
opencv\_datasets3420.lib  
opencv\_datasets3420d.lib  
opencv\_dpm3420.lib  
opencv\_dpm3420d.lib  
opencv\_face3420.lib  
opencv\_face3420d.lib  
opencv\_features2d3420.lib  
opencv\_features2d3420d.lib  
opencv\_flann3420.lib  
opencv\_flann3420d.lib  
opencv\_fuzzy3420.lib  
opencv\_fuzzy3420d.lib  
opencv\_hfs3420.lib  
opencv\_hfs3420d.lib  
opencv\_highgui3420.lib  
opencv\_highgui3420d.lib  
opencv\_imgcodecs3420.lib  
opencv\_imgcodecs3420d.lib  
opencv\_imgproc3420.lib  
opencv\_imgproc3420d.lib  
opencv\_img\_hash3420.lib  
opencv\_img\_hash3420d.lib  
opencv\_line\_descriptor3420.lib  
opencv\_line\_descriptor3420d.lib  
opencv\_ml3420.lib  
opencv\_ml3420d.lib  
opencv\_objdetect3420.lib  
opencv\_objdetect3420d.lib  
opencv\_optflow3420.lib  
opencv\_optflow3420d.lib  
opencv\_phase\_unwrapping3420.lib  
opencv\_phase\_unwrapping3420d.lib  
opencv\_photo3420.lib  
opencv\_photo3420d.lib  
opencv\_plot3420.lib  
opencv\_plot3420d.lib  
opencv\_reg3420.lib  
opencv\_reg3420d.lib  
opencv\_rgbd3420.lib  
opencv\_rgbd3420d.lib  
opencv\_saliency3420.lib  
opencv\_saliency3420d.lib  
opencv\_shape3420.lib  
opencv\_shape3420d.lib  
opencv\_stereo3420.lib  
opencv\_stereo3420d.lib  
opencv\_stitching3420.lib  
opencv\_stitching3420d.lib  
opencv\_structured\_light3420.lib  
opencv\_structured\_light3420d.lib  
opencv\_superres3420.lib  
opencv\_superres3420d.lib  
opencv\_surface\_matching3420.lib  
opencv\_surface\_matching3420d.lib  
opencv\_tracking3420.lib  
opencv\_tracking3420d.lib  
opencv\_video3420.lib  
opencv\_video3420d.lib  
opencv\_videoio3420.lib  
opencv\_videoio3420d.lib  
opencv\_videostab3420.lib  
opencv\_videostab3420d.lib  
opencv\_xfeatures2d3420.lib  
opencv\_xfeatures2d3420d.lib  
opencv\_ximgproc3420.lib  
opencv\_ximgproc3420d.lib  
opencv\_xobjdetect3420.lib  
opencv\_xobjdetect3420d.lib  
opencv\_xphoto3420.lib  
opencv\_xphoto3420d.lib

---

<div class="post-metadata">

**Author:** ![mericgeren](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mericgeren](https://forum.opencv.org/u/mericgeren)\
**Post date:** [May 22, 2024, 10:38am UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/13 "2024-05-22T10:38:52Z")

</div>

I have found how to solve the issue:

1. I have opened the .sln file of the project.
2. Then from the topbar, clicked on “Project”.
3. From the dropdown opened, clicked on “Properties TheopenCVProject”.
4. In properties window selected “Linker” and "  
Link Library Dependencies".
5. Then Added Debug libraries, methods of which are mentioned in error messsages.

After following these steps build was successful.

---

<div class="post-metadata">

**Author:** ![laurent.berger](https://avatars.discourse-cdn.com/v4/letter/l/ec9cab/32.png) [@laurent.berger](https://forum.opencv.org/u/laurent.berger)\
**Post date:** [May 22, 2024, 4:42pm UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/14 "2024-05-22T16:42:01Z")

</div>

["LNK2001 unresolved symbol" Erros about "cv::" Classes and Methods When Building a C++ Project with OpenCV and CUDA · Issue #25599 · opencv/opencv · GitHub](https://github.com/opencv/opencv/issues/25599) ?

---

<div class="post-metadata">

**Author:** ![mericgeren](https://avatars.discourse-cdn.com/v4/letter/m/3ec8ea/32.png) [@mericgeren](https://forum.opencv.org/u/mericgeren)\
**Post date:** [May 27, 2024, 11:24am UTC](https://forum.opencv.org/t/i-get-unresolved-external-symbol-error-when-trying-to-build-a-c-project-with-opencv-and-cuda/17662/15 "2024-05-27T11:24:27Z")

</div>

Initially I thought that was a bug. But, closed that after solving it.
