学习openCV,获取LNK2019(未解析的外部符号)
learning openCV, Getting LNK2019 (unresolved external symbol)
我目前正在开始尝试学习 openCV 和 visual studio 2017 以用于工作中的项目。
我目前正在关注 openCV 的一些教程,但是我收到了 8 个 LNK2019 错误。
你们能帮我解决这个问题吗?
总的来说,我对编码还很陌生,所以如果我问任何愚蠢的问题,请提前道歉。
这是我当前的代码:
#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;
}
这些是我的错误:
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
提前致谢
您似乎没有包含必要的依赖项:
您应该关注:https://docs.opencv.org/2.4/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html
里面解释的很详细。搜索:"Additional Dependencies",但您可能应该重新评估您为设置项目所做的其他步骤。
对我来说,这个问题通常是由于链接器没有指向正确的 lib 文件引起的。这是按步骤完成的,首先你需要将 VS 指向包含 lib 文件的文件夹,然后你需要说出你想要哪些 lib 文件。
首先。
项目 > 属性。然后配置属性 > C/C++ > 常规。在 Additional Include Directories 字段中将地址位置添加到 OpenCv lib 文件夹。我的看起来像这样。
OpenCV_3_3_0\build\VC17\lib\Debug
OpenCV_3_3_0\build\VC17\lib\Release
现在我们需要说出我们想要哪些库。所以在 VS 项目属性选项卡中,
转到 Configuration Properties > Linker > Input,然后转到 Additional Dependencies 字段。
您现在需要添加所需库的名称。
opencv_calib3d330.lib是一个例子
所有库都在文件夹中,所以只需继续添加所有库,直到错误消失(取决于您使用的功能取决于您需要哪个库)
如果您没有正确构建 VS17 的库,您将需要按照这些说明进行操作。
我目前正在开始尝试学习 openCV 和 visual studio 2017 以用于工作中的项目。 我目前正在关注 openCV 的一些教程,但是我收到了 8 个 LNK2019 错误。 你们能帮我解决这个问题吗?
总的来说,我对编码还很陌生,所以如果我问任何愚蠢的问题,请提前道歉。
这是我当前的代码:
#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;
}
这些是我的错误:
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
提前致谢
您似乎没有包含必要的依赖项: 您应该关注:https://docs.opencv.org/2.4/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html
里面解释的很详细。搜索:"Additional Dependencies",但您可能应该重新评估您为设置项目所做的其他步骤。
对我来说,这个问题通常是由于链接器没有指向正确的 lib 文件引起的。这是按步骤完成的,首先你需要将 VS 指向包含 lib 文件的文件夹,然后你需要说出你想要哪些 lib 文件。
首先。 项目 > 属性。然后配置属性 > C/C++ > 常规。在 Additional Include Directories 字段中将地址位置添加到 OpenCv lib 文件夹。我的看起来像这样。
OpenCV_3_3_0\build\VC17\lib\Debug
OpenCV_3_3_0\build\VC17\lib\Release
现在我们需要说出我们想要哪些库。所以在 VS 项目属性选项卡中, 转到 Configuration Properties > Linker > Input,然后转到 Additional Dependencies 字段。
您现在需要添加所需库的名称。 opencv_calib3d330.lib是一个例子
所有库都在文件夹中,所以只需继续添加所有库,直到错误消失(取决于您使用的功能取决于您需要哪个库)
如果您没有正确构建 VS17 的库,您将需要按照这些说明进行操作。