DNN library not linking w/VisualStudio2019

I was trying to run the classifier example with win 10, Visual Studio 2019 and OpenCV 4.5. I built the libraries in release and debug mode successfully. All the core libraries link properly with the exception of opencv_dnn450d.lib and opencv_dnn450.lib.

I also tried earlier versions of opencv.

error LNK2001: unresolved external symbol "public: __cdecl cv::dnn::dnn4_v20181221::Net::~Net(void)" (??1Net@dnn4_v20181221@dnn@cv@@QEAA@XZ)

please show us the build errors you get

See above. I edited the original post and added the link error.

please present all the steps and details that led you to this error

I built v4.5.1 just yesterday, with VS 2019, and it builds just fine here. maybe get v4.5.1 source and work with that.

Here are the steps I’ve taken to try and create an executable in VS 2019 w/the OpenCV classifier example. note… I added the classifier code as a function into an existing MFC app.

  1. Just to ensure I had no conflicts I created a new drive with a fresh copy of Win 10.

  2. Installed VS2019, cpython 3.7, cmake 3.19, opencv-4.51-vc14_vc15, opencv_contrib-4.4.1

  3. Using cmake I created a build directory, ran configure and generate. no errors

4.Located the ALL_BUILD.vcxproj to build the CV libraries for release and debug. Had no errors. Libraries such as opencv_dnn451d.lib, opencv_core451d.lib showed up in my …build\lib\debug directory.

5.Used pcbuild.proj to to build cpython libraries. (I use this in another part of my app)

  1. Opened an existing x64 MFC app that pulls images from multiple cameras and added a function I named classifier that contained the code verbatim from the opencv classifier example.

  2. Modified my library locations to point to the new library files. Configuration manager-Linker-Input-Additional Dependencies-opencv_dnn451d.lib…etc.

Program compiles but fails to link. I will get 25 link errors if I include none of the newly created libraries, only 9 errors associated with dnn with error LNK2001: unresolved external symbol “public: __cdecl cv::dnn::dnn4_v20181221::Net::~Net(void)” (??1Net@dnn4_v20181221@dnn@cv@@QEAA@XZ) being the first one.

Not being sure which specific library was needed for the Net:: function I pointed to all 49. I think I required only core, highgui, dnn, vidioio an imgproc.

versions of main and contrib source must match, otherwise things can fail. that’s probably not the problem here.

I’m assuming you got sources… but then why are they tagged as vc14/15? did you get source from the git repo or as a download?

vc14/15 are Visual Studio 2015/2017… VS 2019 is “vc16”. that leads to some likelihood of incompatibility.

you need to link them if you use them. if you don’t, you will get linker errors. your first post showed a linker error that says you didn’t tell the linker to link opencv_dnn451.lib or something along those lines

you might need some additional libs that are named with opencv_dnn_<something>451.lib, I see dnn_objdetect and dnn_superres at least.

what classifier example precisely do you refer to?

Interesting. I now see that the version of opencv 4.5.1 was from sourceforge after choosing windows from the opencv website . This time I chose github and a different version of 4.5.1 downloaded. I will build this version and see what happens. As for the classifier example it came from the opencv site, samples/dnn/classification.cpp.

I’m hopefull!

this is the DEBUG library, but the error looks like you build a RELEASE app.

True, I built both with the same results. Sorry I showed the debug error while also discussing the release. I am now in the middle of a new library build with version 4.5.1 from github. Will let you know how it comes out in a few.

OK, I am now able to link my classification app. The problem was that I built the 4.5.1 version I downloaded using the Windows link when I should have used the Github link. The windows zip file was labeled opencv-4.5.1-v14_v15… That should have been a clue when I was using VS2019.

All’s well. Thanks for the help.

for completeness’ sake: the specific version binary package from opencv.org does come with source in addition to binaries. you could have built the source from that package for VS 2019. there is no difference in the source of both packages (except due to different version numbers).