error LNK2019: unresolved external symbol _ Open CV program

霸气de小男生 提交于 2020-01-06 20:23:43

问题


I am learning open CV and for the same i was trying few programs. I am referring to this link. http://docs.opencv.org/modules/contrib/doc/facerec/tutorial/facerec_gender_classification.html

I am using visual studio 10 to run the same, and i think somewhere i have messed up with some configuration. I am facing the same problem in couple of more programs (picked from same source) ,

The error which i get is as follows:-

1>main.obj : error LNK2019: unresolved external symbol "int __cdecl cv::waitKey(int)" (?waitKey@cv@@YAHH@Z) referenced in function __catch$_main$0

1>main.obj : error LNK2019: unresolved external symbol "class cv::Mat __cdecl cv::subspaceReconstruct(class cv::_InputArray const &,class cv::_InputArray const &,class cv::_InputArray const &)" (?subspaceReconstruct@cv@@YA?AVMat@1@ABV_InputArray@1@00@Z) referenced in function __catch$_main$0

..... (more such unresolved external symbol error)

1>main.obj : error LNK2001: unresolved external symbol "public: virtual bool __thiscall cv::_InputArray::empty(void)const " (?empty@_InputArray@cv@@UBE_NXZ)

1>c:\users\isenses\documents\visual studio 2010\Projects\gender_classification\Debug\gender_classification.exe : fatal error LNK1120: 37 unresolved externals

1>

1>Build FAILED.

1>Time Elapsed 00:00:00.36

========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

My Project Properties are as follows:-

Properties->Configuration Properties ->Debugging->command arguments->C:\Users\isenses\Documents\Visual Studio 2010\Projects\gender_classification\csv.txt

Properties->Configuration Properties ->VC++ directories->Include directories->(added C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\lib &
C:\openCV_2.4\opencv\build\x86\vc10\lib)

C/C++->general->additional include directories (added include path of openCV ie:- C:\openCV_2.4\opencv\build

Linker->General--- Enable incremental linking=no

Additional Library directories=C:\Program Files %28x86%29\Microsoft Visual Studio 10.0\VC\lib

C:\openCV_2.4\opencv\build\x86\vc10

linker->System---SubSystem= /SUBSYSTEM:CONSOLE

Linker->Input--- additional dependencies= wsock32.lib opencv_contrib2411d.lib

opencv_calib3d2411d.lib

opencv_ml2411d.lib

opencv_objdetect2411d.lib

Thank you.


回答1:


Thanks to @miki i was able to build the file successfully. The solution to my problem was:-

  1. adding proper additional Dependencies in properties->linker->input.
  2. Adding libraries path in windows environment variables.
  3. I had not used proper additional dependencies as pointed by @miki and as quoted by him "well you also have to link opencv_coreXXX,opencv_highguiXXX, opencv_imgprocXXX etc... (with trailing "d" if in debug) in your Linker->Input--- additional dependencies"

Thanks again




回答2:


I want to add an answer to this because I feel the documentation on the opencv site needs to be updated. I followed the tutorial and could not get the library to link. After many permutations I decided to look at the .lib files. My problem was quite simple. The lib files in the opencv tutorial are not complete. Specifically my lib directory includes three more lib files. I added three extra lib files to visual studio linker and the external symbol problem was solved. I am unsure why this is the case because I was only trying to use functions contained within the core module. Anyway, hopefully this will help someone.

I am using opencv 3 and visual studio 2017.



来源:https://stackoverflow.com/questions/31832569/error-lnk2019-unresolved-external-symbol-open-cv-program

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!