c++ - 使用 opencv 和 Visual Studio 2019 安装 BGSlibrary 时出现问题
问题描述
所以我一周前问了一个类似的问题,并被发送到一个线程以查找链接器错误。我现在已经阅读了所有错误,并使用 cmake 对包括 OpenCV 在内的所有内容进行了完整的全新安装。
问题是当我现在正确添加项目时,我仍然会遇到相同的链接器错误。我已经使用 cmake 构建了项目,并将库文件添加到依赖项中,并将库目标添加到库目录中。
https://github.com/andrewssobral/bgslibrary/tree/master 这是这个库,我按照 cmake 步骤作为集成步骤,老实说,我只是迷失了我现在能做的事情。
如果有人可以用婴儿步骤向我解释这一点,我将不胜感激,因为我很确定我做的一切都是正确的,但仍然得到错误的答案
我所采取的所有步骤的照片: 初始克隆、Cmake、在发布模式下成功构建之后。执行 1 行代码后的错误,引发错误的实现
请我真的迷路了。
PS:在遵循 Drescherjms 的回答后,我重建了我的 OpenCV,但这次是在发布模式下(正如他们所指出的,错误是它找不到那个 .lib 文件)。这解决了没有发现的问题,但在构建时添加了许多在此之前不存在的新链接器错误。我将在此处粘贴其中的一些:
3>Main.obj : error LNK2019: unresolved external symbol "void __cdecl cv::destroyAllWindows(void)" (?destroyAllWindows@cv@@YAXXZ) referenced in function "public: static void __cdecl bgslibrary::Main::start(int,char const * *)" (?start@Main@bgslibrary@@SAXHPEAPEBD@Z)
3>Main.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z) referenced in function "public: static void __cdecl bgslibrary::Main::start(int,char const * *)" (?start@Main@bgslibrary@@SAXHPEAPEBD@Z)
3>VideoAnalysis.obj : error LNK2001: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z)
3>VideoCapture.obj : error LNK2001: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z)
3>PreProcessor.obj : error LNK2019: unresolved external symbol "public: class cv::Mat __cdecl cv::Mat::clone(void)const " (?clone@Mat@cv@@QEBA?AV12@XZ) referenced in function "public: class cv::Mat __cdecl bgslibrary::PreProcessor::getGrayScale(void)" (?getGrayScale@PreProcessor@bgslibrary@@QEAA?AVMat@cv@@XZ)
3>PreProcessor.obj : error LNK2019: unresolved external symbol "public: bool __cdecl cv::Mat::empty(void)const " (?empty@Mat@cv@@QEBA_NXZ) referenced in function "public: void __cdecl bgslibrary::PreProcessor::applyCanny(class cv::Mat const &,class cv::Mat &)" (?applyCanny@PreProcessor@bgslibrary@@QEAAXAEBVMat@cv@@AEAV34@@Z)
3>VideoCapture.obj : error LNK2001: unresolved external symbol "public: bool __cdecl cv::Mat::empty(void)const " (?empty@Mat@cv@@QEBA_NXZ)
3>PreProcessor.obj : error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow@cv@@YAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV_InputArray@1@@Z) referenced in function "public: void __cdecl bgslibrary::PreProcessor::process(class cv::Mat const &,class cv::Mat &)" (?process@PreProcessor@bgslibrary@@QEAAXAEBVMat@cv@@AEAV34@@Z)
3>VideoCapture.obj : error LNK2001: unresolved external symbol "void __cdecl cv::imshow(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::_InputArray const &)" (?imshow@cv@@YAXAEBV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@AEBV_InputArray@1@@Z)
3>PreProcessor.obj : error LNK2019: unresolved external symbol "void __cdecl cv::GaussianBlur(class cv::_InputArray const &,class cv::_OutputArray const &,class cv::Size_<int>,double,double,int)" (?GaussianBlur@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@V?$Size_@H@1@NNH@Z) referenced in function "public: void __cdecl bgslibrary::PreProcessor::process(class cv::Mat const &,class cv::Mat &)" (?process@PreProcessor@bgslibrary@@QEAAXAEBVMat@cv@@AEAV34@@Z)
3>PreProcessor.obj : error LNK2019: unresolved external symbol "void __cdecl cv::Canny(class cv::_InputArray const &,class cv::_OutputArray const &,double,double,int,bool)" (?Canny@cv@@YAXAEBV_InputArray@1@AEBV_OutputArray@1@NNH_N@Z) referenced in function "public: void __cdecl bgslibrary::PreProcessor::applyCanny(class cv::Mat const &,class cv::Mat &)" (?applyCanny@PreProcessor@bgslibrary@@QEAAXAEBVMat@cv@@AEAV34@@Z)
3>PreProcessor.obj : error LNK2019: unresolved external symbol "double __cdecl cv::threshold(class cv::_InputArray const &,class cv::_OutputArray const &,double,double,int)" (?threshold@cv@@YANAEBV_InputArray@1@AEBV_OutputArray@1@NNH@Z) referenced in function "public: void __cdecl bgslibrary::PreProcessor::applyCanny(class cv::Mat const &,class cv::Mat &)" (?applyCanny@PreProcessor@bgslibrary@@QEAAXAEBVMat@cv@@AEAV34@@Z)
并且还添加了这些警告以防万一它们有用
3>D:\GitRepos\opencv\build\lib\Release\opencv_gapi452.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
3>D:\GitRepos\opencv\build\lib\Release\opencv_highgui452.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
3>D:\GitRepos\opencv\build\lib\Release\opencv_ml452.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
3>D:\GitRepos\opencv\build\lib\Release\opencv_objdetect452.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
3>D:\GitRepos\opencv\build\lib\Release\opencv_photo452.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
3>D:\GitRepos\opencv\build\lib\Release\opencv_stitching452.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
3>D:\GitRepos\opencv\build\lib\Release\opencv_video452.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
3>D:\GitRepos\opencv\build\lib\Release\opencv_calib3d452.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
3>D:\GitRepos\opencv\build\lib\Release\opencv_dnn452.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
3>D:\GitRepos\opencv\build\lib\Release\opencv_features2d452.lib : warning LNK4272: library machine type 'x86' conflicts with target machine type 'x64'
解决方案
对于至少知道如何在 Visual Studio 2019 中安装库和进行设置的人来说,我的问题是我正在以不同的配置构建不同的版本。
我在 Debug Win32 和 BgsLibrary 中构建了 OpenCV,我尝试在 Release x64 中构建。在 drescherjm 谈到可能存在于 OpenCV 构建中的问题之后,我从头开始重建 OpenCV,但这次是在 Release Win32 中(因为 bgslibrary 要求您在 Release 中构建)。之后,我又从头开始构建 bgslibrary,但这次也是在 Release Win32 中。之后,它只是链接了所有库并将 .dll 位置添加到我的路径中,并且它起作用了!
推荐阅读
- python - Python 中的烛台颜色值不适用
- python - 如何尝试一些东西,如果它失败了尝试别的东西?
- html - 绝对位置 div 的 Popper.js 工具提示放置(引导程序)
- python - 主机名与自签名 ssl python3 请求不匹配
- c++ - 如何阻止使用 std::thread 创建的线程中的某些信号?
- node.js - Mongoose 查询从同一表中的数组中查找名称并从该表中获取其全部数据
- jenkins - Jenkins:archiveArtifacts - 多个不同的文件
- java - 嵌套异常是 java.lang.NumberFormatException: For input string/ Multipart file and json data to spring boot
- javascript - Error in Microsoft Bot Emulator: connect ECONNREFUSED 127.0.0.1
- python - 我本地 Jupter 中 Numpy.sum() 的意外返回值