c++ – The release is compiled with the debug library and vice versa


A few months later, I decided to build my old project that uses the Python runtime. And it was a miracle: the release wouldn’t build, there was an unresolved external symbol Py_Initialize, etc. I swapped the libraries:

#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,"python311.lib")
#                       elif defined(Py_LIMITED_API)
#                               pragma comment(lib,"python3.lib")
#                       else
#                               pragma comment(lib,"python311_d.lib")
#                       endif /* _DEBUG */
#               endif /* _MSC_VER */
#       endif /* Py_BUILD_CORE */
#endif /* MS_COREDLL */

And everything worked. Only the release now requires a debug build of Python(python311_d.dll).
Does anyone know the reason for this magic?

My configuration:

  • Microsoft Visual Studio Community 2022 17.14.13 (August 2025)

  • msvc sdk v 143

  • Release runtime flag /MT

  • Debug runtime flag /MTd

  • The debug has the _DEBUG macro installed, while the release has
    NODEBUG.

Leave a Reply

Your email address will not be published. Required fields are marked *