I'm a newbie and I'm trying to use opencv with vs2022 for the first time.In vs2022, I created a new empty project and installed opencv using nuget. Next, I created a source file named main.cpp and wrote the following code:
#include <cstdio>
#include <string>
#include <opencv2/opencv.hpp>
using namespace cv;
using namespace std;
int main() {
Mat image = imread("112.jpg", IMREAD_COLOR);
if (image.empty()) {
cout << "could not find" << endl;
}
imshow("Image", image);
return 0;
}
When I run the project I get the following error:
1>------ Build started: Project: Project5, Configuration: Debug x64 ------
1>main.obj : error LNK2019: unresolved external symbol "void __cdecl cv::fastFree(void *)" (?fastFree@cv@@YAXPEAX@Z) referenced in function "public: __cdecl cv::Mat::~Mat(void)" (??1Mat@cv@@QEAA@XZ)
1>main.obj : error LNK2019: unresolved external symbol "public: __cdecl cv::_InputArray::_InputArray(class cv::Mat const &)" (??0_InputArray@cv@@QEAA@AEBVMat@1@@Z) referenced in function main
1>main.obj : error LNK2019: unresolved external symbol "public: void __cdecl
I tried for a long time but couldn't find the reason, because as far as the information I looked up, no one had this error. After they installed opencv using nuget, they could use it normally.
I tried uninstalling opencv and reinstalling but to no avail
The package you are using is a very old version package upload by personal, even it is support native code.
Nuget Package is mainly a package for .net environment projects.
I notice the really opencv project is here:
https://github.com/opencv/opencv
And it still updates yesterday.
For your C++ project, you could search the C++ packages and install packages via here:
This is the official document of it:
And this is the examples:
I think this sample has a part of code which is similar to what you are doing:
By the way, you can take a look of this answer, he can success using another C++ library via my direction and he shared the detailed steps: