Hey there,
this question is partly related to OpenCV and partly debugging an executable in general, though the latter case is not really part of this forum. This is a long post, but I have the feeling it is better to elaborate on this, as the devil is in the details, and most likely a single lib/ dll is missing etc.
I am working with VS 2013 and have an executable, let's name it main
, which uses OpenCV functionality. I want to debug into one of the functions, more precisely computeDisparitySGBM
in stereoSGBM.cpp. For this reason I build main
in debug configuration and specify it in my OpenCV VS project (see https://docs.microsoft.com/en-us/visualstudio/debugger/how-to-debug-from-a-dll-project).
The trouble starts earlier, as I can not build the debug configuration of main
(I can build release though) and receive a bunch of linker errors:
error LNK2019: unresolved external symbol "void __cdecl cv::imshow(class cv::String const &,class cv::debug_build_guard::_InputArray const &)" (?imshow@cv@@YAXAEBVString@1@AEBV_InputArray@debug_build_guard@1@@Z) referenced in function main
error LNK2019: unresolved external symbol "class cv::debug_build_guard::_InputOutputArray const & __cdecl cv::noArray(void)" (?noArray@cv@@YAAEBV_InputOutputArray@debug_build_guard@1@XZ) referenced in function "struct std::pair<class cv::mat,class="" cv::mat=""> __cdecl misc::composeStereoRT(class cv::Mat const &,class cv::Mat const &,class cv::Mat const &,class cv::Mat const &)" (?composeStereoRT@misc@@YA?AU?$pair@VMat@cv@@V12@@std@@AEBVMat@cv@@000@Z)
error LNK2019: unresolved external symbol "void __cdecl cv::Rodrigues(class cv::debug_build_guard::_InputArray const &,class cv::debug_build_guard::_OutputArray const &,class cv::debug_build_guard::_OutputArray const &)" (?Rodrigues@cv@@YAXAEBV_InputArray@debug_build_guard@1@AEBV_OutputArray@31@1@Z) referenced in function "struct std::pair<class cv::mat,class="" cv::mat=""> __cdecl misc::composeStereoRT(class cv::Mat const &,class cv::Mat const &,class cv::Mat const &,class cv::Mat const &)" (?composeStereoRT@misc@@YA?AU?$pair@VMat@cv@@V12@@std@@AEBVMat@cv@@000@Z)
Obviously, the linker does not find the objects, though it does not complain about other functions as imread
. The project containing main
was generated using CMake and the dependencies for release and debug config. are identically:
C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_stitching341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_superres341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_videostab341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_aruco341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_bgsegm341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_bioinspired341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_ccalib341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_dnn_objdetect341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_dpm341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_face341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_fuzzy341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_hdf341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_hfs341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_img_hash341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_line_descriptor341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_optflow341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_reg341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_rgbd341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_saliency341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_stereo341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_structured_light341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_surface_matching341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_tracking341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_xfeatures2d341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_ximgproc341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_xobjdetect341.lib C:\Users\local_user\Documents\OpenCV\opencv-3.4.1\build\install\x64\vc12\lib\opencv_xphoto341.lib
For the dlls, I included both paths to the release and debug versions of the dll's to my systems path.
My questions:
1) Why are the dependencies identically? I would expect that the debug config uses the *d.lib. If so, how do I tell CMake to generate the project accordingly? How does the linker than knows + where can I see that the debug version should be used?
2) In Additional Library Directories, there is no OpenCV folder specified. Is this correct and if so why is it not needed? (PCL does add its folders...)
3) Why are there libs anyway when I use dynamic linking? (As you can see, my background is not computer science.) Or are the lib's needed during build process (the linker phase) regardless of static or dynamic linking?
4) I would like to know, in which lib/ dll the missing symbols are located and check if they are in the lib/dll folder. However, from the OpenCV documentation (https://docs.opencv.org/3.4.1/d9/d0c/group__calib3d.html#ga61585db663d9da06b68e70cfbf6a1eac), I can't get a hint. Where do I find it?
Finally, we ware done! Thank you already!