none
Issues Running Sample Code Stitcher.cpp from OpenCV in VS 2017 RRS feed

  • Question

  • Hello,

    I'm new to VS, and I'm trying to run the stitcher.cpp sample code from OpenCV's GitHub.

    I want to take two pictures and make them into one picture panorama style.  When I copy the code from GitHub into VS, I get many errors like the two below:

    Error LNK2019 unresolved external symbol "bool __cdecl cv::imwrite(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > const &,class cv::debug_build_guard::_InputArray const &,class std::vector<int,class std::allocator<int> > const &)" (?imwrite@cv@@YA_NABV?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@ABV_InputArray@debug_build_guard@1@ABV?$vector@HV?$allocator@H@std@@@3@@Z) referenced in function _main hello-realsense C:\Program Files (x86)\Intel RealSense SDK 2.0\samples\hello-realsense\rs-hello-realsense.obj 1 

     

    Error LNK2019 unresolved external symbol "class cv::Mat __cdecl cv::imread(class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > 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 "int __cdecl parseCmdArgs(int,char * *)" (?parseCmdArgs@@YAHHPAPAD@Z) hello-realsense C:\Program Files (x86)\Intel RealSense SDK 2.0\samples\hello-realsense\rs-hello-realsense.obj 1 

    Can anyone provide insight into how I can correct these errors? 

    Thank you for your help.


    Monday, June 17, 2019 5:37 PM

All replies

  • You haven't linked with the OpenCV library.  The #include file tells it what the functions and classes look like, but you need to tell it where to find the library so it can link with actual code.

    Tim Roberts | Driver MVP Emeritus | Providenza &amp; Boekelheide, Inc.

    • Proposed as answer by Guido Franzke Tuesday, June 18, 2019 6:20 AM
    Monday, June 17, 2019 5:39 PM
  • Thank you for the quick reply. I linked the libraries that were called for in the code by doing the following:

    project -> properties ->VC++ Directories -> include directories -> edit

    Then I added the path where the files here are located:

    #include "opencv2/imgcodecs.hpp"
    #include "opencv2/highgui.hpp"
    #include "opencv2/stitching.hpp"

    There are no direct errors in the code before building the project, but I get a handful of wordy errors. I'm not sure what I am missing. 


    Monday, June 17, 2019 5:51 PM
  • If I am missing any relevant information that may be helpful, please let me know. I am obviously new to the forums and VS :)
    Monday, June 17, 2019 6:28 PM
  • Hello,

    Thank you for posting here.

    >>I linked the libraries that were called for in the code by doing the following:

    >>project -> properties ->VC++ Directories -> include directories -> edit

    You haven't linked with the OpenCV library. The step which you said is right. It tells the system where the header file is, so your program has no direct errors, and you need the following two steps to complete the configuration.

    project -> properties -> VC++ Directories -> Library Directories -> edit

    project -> properties -> Linker->Input-> Additional Dependencies -> edit

    In fact, we also need to configure the environment variables before the above operations. If you haven't configured it, please follow the step below.

    This PC-> Advanced system settings -> Environment variables -> System variables -> Path -> edit 

    These are the whole process of OpenCV library configuration. If you have any other questions, please feel free to contact us.

    Best Regards,

    Suarez Zhou



    Tuesday, June 18, 2019 1:41 AM
  • Hello,

    here is a nice documentation how to include OpenCV in VS: https://docs.opencv.org/2.4/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html

    Regards, Guido

    Tuesday, June 18, 2019 6:23 AM
  • If I am missing any relevant information that may be helpful, please let me know. I am obviously new to the forums and VS :)

    As mentioned earlier you are missing lib file here . So in that case you can use either Additional Dependencies to add library  to your project or simply use #pragma comment(lib,"lib file path") in your source file.



    Rupesh Shukla

    Tuesday, June 18, 2019 2:08 PM