Issue
So I asked a similar question a week ago, and got send to a thread for linker errors. I have now read through all of the errors and did a full clean install of everything including OpenCV, all with cmake.
The problem is that I still get the same linker errors when I now add the project properly. I have built the project using cmake and added the library file to dependencies and the library destination to the library directories.
https://github.com/andrewssobral/bgslibrary/tree/master It is this library, and I followed the cmake steps as the integration steps and I am honestly just lost with what I can do now.
If someone could please explain this to me in baby steps it would be really appreciated, as I am pretty sure I did everything right and still am getting the wrong answer
Photo's of all the steps I have taken: Initial Clone, Cmake, After a succesful build on release mode. Errors after implementing 1 line of code, The implementation that brings up the error
Please I am genuinely just lost.
PS: After following Drescherjms answers I rebuild my OpenCV but this time on release mode (as they noted, the error was that it couldn't find that .lib file). This solved the problem of not finding that but added a load of new linker errors that didn't exist before this while building. I will paste a few of them here:
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)
and also added these warnings just in case they are useful
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'
Solution
The easiest way to make it work with cmake
and MSVC
is use vcpkg.
So follow instruction of vcpkg
(build this tool), install OpneCV
using that tool.
Then in CMakeLists.txt
just use find_package(OpenCV REQUIRED)
and you are almost at home.
For more details see OpenCV documentation how to use OpenCV with a cmake
.
Extra gain is that this should work also with Linux if someone will install OpenCV with package manager and on MacOS (is someone is using Home Brew).
Answered By - Marek R