Reputation: 37
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
Upvotes: 1
Views: 11684
Reputation: 94
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)
If you havent correctly built the libs for VS17 you will need to follow these instructions.
Upvotes: 0
Reputation: 1194
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.
Upvotes: 0