# Build error in Windows in debug mode due to python312\_d.lib

**URL:** <https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781>\
**Category:** Development\
**Tags:** build\
**Created:** [July 20, 2025, 12:42pm UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781 "2025-07-20T12:42:27Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 20, 2025, 12:42pm UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781/1 "2025-07-20T12:42:27Z")

</div>

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.

```txt
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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [July 20, 2025, 12:54pm UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781/2 "2025-07-20T12:54:53Z")

</div>

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`:

```auto
...
/* 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:

```auto
/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.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [July 30, 2025, 11:48am UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781/3 "2025-07-30T11:48:27Z")

</div>

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 🙂 Thanks a lot!

---

<div class="post-metadata">

**Author:** ![Benjamin\_Bennett](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/benjamin_bennett/32/80742_2.png) [@Benjamin\_Bennett](https://discourse.slicer.org/u/Benjamin_Bennett)\
**Post date:** [August 3, 2025, 9:13pm UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781/4 "2025-08-03T21:13:50Z")

</div>

> [@lassoan](#):
>
> ` pragma comment(lib,"python312_d.lib")`

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

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 3, 2025, 9:30pm UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781/5 "2025-08-03T21:30:58Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [August 3, 2025, 11:01pm UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781/6 "2025-08-03T23:01:53Z")

</div>

Corresponding patch should be added to [https://github.com/python-cmake-buildsystem/cpython?tab=readme-ov-file#available-branches](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](https://github.com/python-cmake-buildsystem/python-cmake-buildsystem/tree/master/patches/3.12)

---

<div class="post-metadata">

**Author:** ![jcfr](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/jcfr/32/17825_2.png) [@jcfr](https://discourse.slicer.org/u/jcfr)\
**Post date:** [August 3, 2025, 11:07pm UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781/7 "2025-08-03T23:07:08Z")

</div>

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

- [PythonQtPythonInclude.h](https://github.com/commontk/PythonQt/blob/7f7105ba9ec59d719ded80090e049fa85ad76e79/src/PythonQtPythonInclude.h#L95)
- [vtkPython.h](https://github.com/Slicer/VTK/blob/slicer-v9.5.0-2025-06-19-e70c856bd/Utilities/Python/vtkPython.h#L40)

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

---

<div class="post-metadata">

**Author:** ![Benjamin\_Bennett](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/benjamin_bennett/32/80742_2.png) [@Benjamin\_Bennett](https://discourse.slicer.org/u/Benjamin_Bennett)\
**Post date:** [August 4, 2025, 1:05am UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781/8 "2025-08-04T01:05:56Z")

</div>

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 .

---

<div class="post-metadata">

**Author:** ![lassoan](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/lassoan/32/13_2.png) [@lassoan](https://discourse.slicer.org/u/lassoan)\
**Post date:** [August 18, 2025, 1:05am UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781/9 "2025-08-18T01:05:07Z")

</div>

I’ve created a pull request with a simple fix:

> <https://github.com/Slicer/Slicer/pull/8651>
>
> Fixes the build error described in https://discourse.slicer.org/t/build-error-in…-windows-in-debug-mode-due-to-python312-d-lib/43781/8
> 
> Python.h cannot be directly included in an application on Windows, because the linked library is specified in the Python.h header file, but the application's build mode (Debug, Release, etc.) is not always the same as Python's build mode (always Release in Slicer). This is a well-known issue and workarounds are implemented in PythonQt and VTK: https://github.com/commontk/PythonQt/blob/7f7105ba9ec59d719ded80090e049fa85ad76e79/src/PythonQtPythonInclude.h#L95 https://github.com/Slicer/VTK/blob/slicer-v9.5.0-2025-06-19-e70c856bd/Utilities/Python/vtkPython.h#L40
> 
> Since including "PythonQt.h" automatically includes "Python.h" with the appropriate workarounds, the best solution to the build error is simply not including "Python.h" directly.

In [latest Python version](https://github.com/python/cpython/blob/bc2872445b2aee4bb4e001d4171489d7123b1daf/PC/pyconfig.h#L332C36-L332C44) a separate `Py_DEBUG` option is used, so the Python build mode can be specified separately from the application’s build mode.

---

<div class="post-metadata">

**Author:** ![cpinter](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.slicer.org/cpinter/32/7995_2.png) [@cpinter](https://discourse.slicer.org/u/cpinter)\
**Post date:** [August 18, 2025, 9:41am UTC](https://discourse.slicer.org/t/build-error-in-windows-in-debug-mode-due-to-python312-d-lib/43781/10 "2025-08-18T09:41:25Z")

</div>

Thank you very much Andras! What a nice simple fix!
