1

I am currently starting to try and learn openCV and visual studio 2017 for a project at work. I am currently following a few tutorial from openCV, however I am getting 8 LNK2019 errors. Would you guys be able to help me with this?

I am quite new to coding in general so sorry in advance if I'm asking any stupid questions.

This is my current code:

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main(int argc, char** argv)
{
 String imageName( "HappyFish.jpg" ); //by default
 if (argc > 1)
 {
 imageName = argv[1];
 }
 Mat image;
 image = imread(samples::findFile(imageName), IMREAD_COLOR); //Read the file
 if (image.empty()) //checking for valid input
 {
 cout << "Could not open or find the image" << std::endl;
 return -1;
 }
 namedWindow("Display window", WINDOW_AUTOSIZE); //create a window for the display
 imshow("Display window", image); //showing our image inside the window
 waitKey(0); //Wait for a keystroke in the window
 return 0;
}

And these are my errors:

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPAX@Z) referenced in function "public: __thiscall cv::Mat::~Mat(void)" (??1Mat@cv@@QAE@XZ) Open cv test C:\Users\BRR\source\repos\Open cv test\Open cv test\Open cv test.obj 1

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "void __cdecl cv::error(int,class std::basic_string,class std::allocator> const &,char const *,char const *,int)" (?error@cv@@YAXHABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@PBD1H@Z) referenced in function "public: class cv::Mat & __thiscall cv::Mat::operator=(class cv::Mat &&)" (??4Mat@cv@@QAEAAV01@$$QAV01@@Z) Open cv test C:\Users\BRR\source\repos\Open cv test\Open cv test\Open cv test.obj 1

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "public: void __thiscall cv::Mat::deallocate(void)" (?deallocate@Mat@cv@@QAEXXZ) referenced in function "public: void __thiscall cv::Mat::release(void)" (?release@Mat@cv@@QAEXXZ) Open cv test C:\Users\BRR\source\repos\Open cv test\Open cv test\Open cv test.obj 1

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "class std::basic_string,class std::allocator> __cdecl cv::samples::findFile(class std::basic_string,class std::allocator> const &,bool,bool)" (?findFile@samples@cv@@YA?AV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV34@_N1@Z) referenced in function _main Open cv test C:\Users\BRR\source\repos\Open cv test\Open cv test\Open cv test.obj 1

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string,class std::allocator> const &,int)" (?imread@cv@@YA?AVMat@1@ABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function _main Open cv test C:\Users\BRR\source\repos\Open cv test\Open cv test\Open cv test.obj 1

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "void __cdecl cv::namedWindow(class std::basic_string,class std::allocator> const &,int)" (?namedWindow@cv@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@H@Z) referenced in function _main Open cv test C:\Users\BRR\source\repos\Open cv test\Open cv test\Open cv test.obj 1

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z) referenced in function _main Open cv test C:\Users\BRR\source\repos\Open cv test\Open cv test\Open cv test.obj 1

Severity Code Description Project File Line Suppression State Error LNK2019 unresolved external symbol "void __cdecl cv::imshow(class std::basic_string,class std::allocator> const &,class cv::debug_build_guard::_InputArray const &)" (?imshow@cv@@YAXABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV_InputArray@debug_build_guard@1@@Z) referenced in function _main Open cv test C:\Users\BRR\source\repos\Open cv test\Open cv test\Open cv test.obj 1

thanks in advance

asked Mar 17, 2020 at 10:50

2 Answers 2

0

For me this issue is normally caused by not having the linker pointed to the correct lib files. This is completed in to steps, first you need to point VS to the folder that contains the lib files, then you need to say which lib files you want.

First. Project>Properties. Then Configuration Properties> C/C++>General. The in the field Additional Include Directories add the address location to the OpenCv lib folder. Mine looks like this.

OpenCV_3_3_0\build\VC17\lib\Debug

OpenCV_3_3_0\build\VC17\lib\Release

Now we need to say which libs we want. So In the VS project properties tab, Go to Configuration Properties> Linker> Input and then Additional Dependencies field.

You will now need to add the names of the libs you want. opencv_calib3d330.lib is an example

All the libs are in the folder so just keep adding all the libs till the error goes away (depending on which feature you use depends on which lib you need)

Lib folder for Release

If you havent correctly built the libs for VS17 you will need to follow these instructions.

https://docs.opencv.org/2.4/doc/tutorials/introduction/windows_install/windows_install.html#windows-installation

answered Mar 17, 2020 at 11:11
Sign up to request clarification or add additional context in comments.

13 Comments

Is there a place where I can find a list of these libs? And what Folder are you refering to at the end of your answer?
Hey Bartrae, I cant point to the folder, because it depends on your own path names. But its the lib folder in the build section of your opencv. I can help further if you show the folder structure of your opencv build. As for a list, the folder contains all the files, so that is the list, keep adding the files till there is no more error (Not a great answer but the files change depending on the features you use)
I added a picture in my answer
If i understand correctly, you mean a path like this "C:\lib\Build\opencv\lib" right?, in there I've got two folders , "Debug" and "Release". There are a three .lib files in those folders.
Yes those folders, and you need to add the two different addresses depending if your build is Debug or Release. There is only three? What are they?
|
0

It seems you did not include the necessary dependencies: You should follow: https://docs.opencv.org/2.4/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html

It's explained in great detail there. Search for: "Additional Dependencies", but you should probably re-evaluate the other steps you've made to set up the project.

answered Mar 17, 2020 at 11:02

8 Comments

Thank you, I will look at this an will come back to you.
I've looked at the guide, a few things are a bit different since they appear to be using a different visual studio version. however when I get to the point where a need to add a load of .lib files in Project >Properties>Linker>Input I seem to be encountering a problem. It seems I've only got 3 .lib files in the lib folder (see the discussion with Chris)
Ok, so you're using a newer version: but you can find a tutorial for that as well: medium.com/@subwaymatch/opencv-410-with-vs-2019-3d0bc0c81d96 Just add opencv_world. But it's the same thing, only change is that the libraries have been grouped into one binary
would you recommend doing a complete reinstall of OpenCV following the guide you linked in stead of trying to salvage what I've got? Again, I'm quite new to this sorry if I'm asking dumb questions.
It's up to you :) It's probably salvageable, but I would usually start from scratch.
|

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.