0

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.

Mayank
  • 353
  • 6
  • 20
  • _m pretty sure i have got all the configurations right_ probably you're not! Show Include and Libraries Directories from your project properties. – Miki Aug 05 '15 at 12:33
  • @Miki Well i did miss the input section in linker. I add the additional Dependencies. But still i get the error--- – Mayank Aug 05 '15 at 13:40
  • So it's working now? – Miki Aug 05 '15 at 13:41
  • 1>LINK : fatal error LNK1181: cannot open input file 'opencv_contrib2411d.lib' – Mayank Aug 05 '15 at 13:42
  • Have you added it to Linker -> Input? – Miki Aug 05 '15 at 13:43
  • Have a look [here](http://docs.opencv.org/doc/tutorials/introduction/windows_visual_studio_Opencv/windows_visual_studio_Opencv.html) – Miki Aug 05 '15 at 13:44
  • path variables were set,but i missed the static libraries setting. But i followed the instructions and everything is on right tracks. I had one doubt which i think might be the reason. Well i have win64bit but visual studio is installed in prog..x86 folder,and all the linking paths that m defining is of 64bit. I hope thats right? – Mayank Aug 05 '15 at 14:15
  • LINK : fatal error LNK1181: cannot open input file 'opencv_contrib2411d.lib' Though on checking the directory manually i am able to find all the lib files m calling. – Mayank Aug 05 '15 at 15:01
  • what's you Library Directory? – Miki Aug 05 '15 at 15:02
  • C:\openCV_2.4\opencv\build\x86\vc10\lib ------my library directory path. well m still on the same error as above but now 33 unresolved externals. – Mayank Aug 05 '15 at 15:46
  • Your project (not your SO) is 32 or 64 bits? You are linking against 32 bit libs (x86) – Miki Aug 05 '15 at 15:48
  • I've just seen your update.. 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 – Miki Aug 05 '15 at 15:50
  • yes m linking against x86 (32 bits) I figured that out. – Mayank Aug 05 '15 at 15:51
  • hey...thank you. It worked. now m at error "the application was unable to start correctly (0xc000007b)" which is a application error. OS bit version issues. working on it.will reply as soon i get it running. In mean while can you also guide me that how u figured the libraries required(for self learning). thank you again Miki :-) – Mayank Aug 05 '15 at 16:17
  • because Mat is in opencv_core, imread is in opencv_highgui, etc... in general core, imgproc and highgui are always needed. – Miki Aug 05 '15 at 16:19

2 Answers2

3

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

Mayank
  • 353
  • 6
  • 20
  • Another thing to keep in mind is that if you add the dependencies in Visual Studio under Properties->Linker->Input is that you cant just paste all the *.lib names as one long string. VS2019 seems to ignore anything after a line break for this field. You have to double click to open the field and add all the *d.lib file names in the specific field editor for it to actually save all the relevant lib names.Purely by chance my HighGui library was linking correctly but nothing else and it was because it just so happened to be the first entry on my list! – Joe Jan 02 '21 at 21:49
1

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.

Paul
  • 11
  • 1