Skip to content

Conversation

@jcfr
Copy link
Contributor

@jcfr jcfr commented Sep 1, 2025

This PR fixes Windows/MSVC build and link issues when PythonQt is built in Debug while linking against a Release Python (e.g., only pythonXY.dll/pythonXY.lib are available).

Summary:

  • Adopt the strategy used in VTK to temporarily undefine _DEBUG only for the Python.h inclusion, while:

    • Pre-including low-level CRT headers before undefining _DEBUG to avoid pulling in release-mode CRT variants inadvertently.
    • Defining _CRT_NOFORCE_MANIFEST and _STL_NOFORCE_MANIFEST on MSVC ≥ 1400 to prevent inconsistent CRT manifest flags.
    • Restoring _DEBUG afterward to keep the rest of the TU in the correct debug configuration.
  • Wrap the behavior with a small guard macro:

    • Introduce PYTHONQT_UNDEF_DEBUG so we can safely re-define _DEBUG only when we actually changed it.
  • All changes are conditioned on PYTHONQT_USE_RELEASE_PYTHON_FALLBACK && _DEBUG.

Motivation:

Without these adjustments, MSVC may:

  • Emit CRT manifest inconsistencies (e.g., _CRT_MANIFEST_DEBUG, _CRT_MANIFEST_RETAIL, _CRT_MANIFEST_INCONSISTENT) across the same Translation Unit.
  • Trigger link errors such as _invalid_parameter_noinfo_noreturn due to mismatched debug/release CRT resolution caused by including system headers with the wrong _DEBUG state.

References:

John Stark and others added 2 commits September 1, 2025 03:04
…elease

Copied most of the contents of `vtkPython.h`

(cherry picked from commit commontk/PythonQt@8a50eaa)

Co-authored-by: Jean-Christophe Fillion-Robin <[email protected]>
By ensuring that "undef" of _DEBUG macro is not done before system
includes, it fixes the issue.

Based on a similar fix in VTK.
See: Kitware/VTK@81d4a72
See: commontk/PythonQt#9
Thanks to @Neosettler for reporting and testing.

Reported-by: Neosettler
(cherry picked from commit commontk/PythonQt@77d8177)
@jcfr
Copy link
Contributor Author

jcfr commented Sep 1, 2025

Suggested commit message if squashing:

fix(windows): Support MSVC Debug build linking against Release Python

This changes how we include `Python.h` on Windows when
`PYTHONQT_USE_RELEASE_PYTHON_FALLBACK` is enabled and `_DEBUG` is set:

* Pre-include low-level CRT/system headers **before** undefining `_DEBUG` to
  avoid pulling release-mode CRT variants in a debug TU.
* Temporarily undefine `_DEBUG` only for `Python.h`, then restore it using a
  `PYTHONQT_UNDEF_DEBUG` guard.
* On MSVC >= 1400, define `_CRT_NOFORCE_MANIFEST` and `_STL_NOFORCE_MANIFEST`
  to prevent manifest inconsistency flags.

This prevents CRT mismatch issues and link errors like
`_invalid_parameter_noinfo_noreturn` when building PythonQt in Debug against a
Release Python.

References:
* kitware/VTK@81d4a72c1195437403f1772559c9c28978818f03
* commontk/PythonQt#9

(cherry-picked from commontk/PythonQt@8a50eaa6, commontk/PythonQt@77d8177)

Co-authored-by: John Stark <[email protected]>
Co-authored-by: Jean-Christophe Fillion-Robin <[email protected]>

@jcfr jcfr changed the title Backport commontk/fix msvc compilation link issues debug build against python release fix(windows): Support MSVC Debug build linking against Release Python Sep 1, 2025
Copy link
Contributor

@mrbean-bremen mrbean-bremen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@mrbean-bremen mrbean-bremen merged commit a131983 into MeVisLab:master Sep 1, 2025
19 checks passed
@jcfr jcfr deleted the backport-commontk/fix-msvc-compilation-link-issues-debug-build-against-python-release branch September 1, 2025 20:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants