Build error in Windows in debug mode due to python312_d.lib

I’ve been building Slicer for a long while using the same scripts. I’ve updated to the latest Slicer main version (from a version maybe a few weeks ago), started a clean build from scratch (removed all build folders) and this latest version does not build due to python312_d.lib is not found when linking qSlicerBaseQTCore.

165>------ Build started: Project: qSlicerBaseQTCore, Configuration: Debug x64 ------
165>LINK : fatal error LNK1104: cannot open file 'python312_d.lib'

Has anyone encountered this error?

@jcfr @jamesobutler

The only mentions of python312_d.lib in any files in all build folders:

In Python-3.12.10/PC/pyconfig.h, python-build/bin/Release/PC/pyconfig.h, and python-install\include\pyconfig.h:

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

In Slicer-build\Base\QTCore\qSlicerBaseQTCore.dir\Debug\qSlicerCoreApplication.obj:

/DEFAULTLIB:"python312_d.lib"

Modifying the pyconfig.h files from:

#                               pragma comment(lib,"python312_d.lib")

to

#                               pragma comment(lib,"python312.lib")

resolves the build problem, so something may have changed in how pyconfig.h is included or in MS_COREDLL, Py_BUILD_CORE, Py_BUILD_CORE_BUILTIN, _MSC_VER, or _DEBUG defines.

1 Like

For the record I have the very same problem with the latest version. We cannot really debug Slicer until this is solved, so unless everyone is on vacation, please try to chime in :slight_smile: Thanks a lot!

do you want to just patch the source? there is already a pythonapplypatches.cmake.

Is there still a reason to just use the release library still on windows? it is change from 2013 i guess the cmake python build is that still case? ef28720

Yes, just change the source (single line of change) and everything works. It is a very quick and easy workaround but of course it should be fixed properly.

@jcfr please have a look at this when you have time.

Is there still a reason to just use the release library still on windows?

The motivation for this is the same as before. When we build the application in Debug mode, we almost always do that to debug the Slicer application or extensions; and not to debug implementation of low-level libraries such as CPython. Building Python in Release mode allows us to have much better Python runtime performance.

Corresponding patch should be added to https://github.com/python-cmake-buildsystem/cpython?tab=readme-ov-file#available-branches and then integrated to https://github.com/python-cmake-buildsystem/python-cmake-buildsystem/tree/master/patches/3.12

Alternatively, the undef of _DEBUG is already taking care of here:

The right solution would then to either add a MRML or Slicer specific header or include Python using the PythonQt or VTK one.

I just added it to the pythonapplypatches . i have a local crude multi-machine build that I use git to sync my builds.

What way is preferred way? I did the patch applying because that is what I found first .