Add opencv resources to my MFC project

asked 2020-01-02 05:04:33 -0500

flaviu2 gravatar image

updated 2020-01-02 05:38:54 -0500

I have successfully compiled the latest OpenCV library (4.2.0). Now, I intend to use it inside my MFC project (in my case). I have tried to include manually the include files, and so on, but this is not productive. I got weird errors:

error C2065: 'CV_RGB2GRAY': undeclared identifier

This reveal that I didn't add the needed OpenCV resources to my project: header files, libraries and dlls ... my question is: how can I add the needed OpenCV resources to my project (MFC in my case) ?

After I corrected the code from above, I got link errors:

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) error LNK2019: unresolved external symbol "void __cdecl cv::error(int,class std::basic_string<char,struct std::char_traits<char="">,class std::allocator<char> > 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: __thiscall cv::Mat::Mat(class cv::Mat &&)" (??0Mat@cv@@QAE@$$QAV01@@Z) error LNK2019: unresolved external symbol "public: void __thiscall cv::Mat::copyTo(class cv::debug_build_guard::_OutputArray const &)const " (?copyTo@Mat@cv@@QBEXABV_OutputArray@debug_build_guard@2@@Z) referenced in function "public: class cv::Mat __thiscall cv::Mat::clone(void)const " (?clone@Mat@cv@@QBE?AV12@XZ) 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) 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 "public: virtual int __thiscall CMyDoc::OnNewDocument(void)" (?OnNewDocument@CMyDoc@@UAEHXZ) 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 "public: virtual int __thiscall CMyDoc::OnNewDocument(void)" (?OnNewDocument@CMyDoc@@UAEHXZ)

so, how can I know what libraries file is missing ?

edit retag flag offensive close merge delete

Comments

This reveal that I didn't add the needed OpenCV resources

no, it reveals that you're using outdated opencv2 code, it would be cv::COLOR_BGR2GRAY now.

which opencv headers exactly do you include in your program ?

berak gravatar imageberak ( 2020-01-02 05:24:15 -0500 )edit

You had right :)

flaviu2 gravatar imageflaviu2 ( 2020-01-02 05:28:31 -0500 )edit

I updated the first post. There is some link errors now ...

flaviu2 gravatar imageflaviu2 ( 2020-01-02 05:39:21 -0500 )edit

I added manually the needed libraries. Seem to go by now.

flaviu2 gravatar imageflaviu2 ( 2020-01-02 08:28:33 -0500 )edit