Building Debug Version of OpenCV

I have successfully downloaded OpenCV source, configured CMake, and generated build files for Visual Studio 2019/Windows 10. I load the solution without any issue and the build proceeds without any issue. However, when the build finishes I find one error saying that the debug version of python39_d.lib was not found.

I don’t need python for what I am doing. CMake detected it and added it to the configuration. I see in the OpenCV source code at pyconfig.h the following code:

/* For an MSVC DLL, we can nominate the .lib files used by extensions */
#ifdef MS_COREDLL

if !defined(Py_BUILD_CORE) && !defined(Py_BUILD_CORE_BUILTIN)

            /* not building the core - must be an ext */

if defined(_MSC_VER)

                    /* So MSVC users need not specify the .lib
                    file in their Makefile (other compilers are
                    generally taken care of by distutils.) */

if defined(_DEBUG)

pragma comment(lib,“python39_d.lib”)

elif defined(Py_LIMITED_API)

pragma comment(lib,“python3.lib”)

else

pragma comment(lib,“python39.lib”)

endif /* _DEBUG */

endif /* _MSC_VER */

endif /* Py_BUILD_CORE */

#endif /* MS_COREDLL */

It appears that this is the only place that python39_d.lib is referenced.

Can I safely ignore this error? Is there a preferred approach to linking with the non-debug version of the library? As I say, I don’t need python for what I am doing because I am working in C++.

Thank you for any insights.

the usual python install does not contain the debug python39_d.lib, it only makes sense to build python bindings in release mode

you can disable the python bindings by setting

BUILD_opencv_python3=OFF
BUILD_opencv_python_bindings_generator=OFF

in cmake.

Thank you for this tip.

The main reason I want to build a debug version is so I can set breakpoints and step through the OpenCV code. That way I can see and understand how OpenCV works better. Also, sometimes OpenCV returns cryptic exceptions and it helps to set a breakpoint where the exception is thrown to understand better what conditions were not met that caused the exception.