Skip to content

Conversation

@jcfr
Copy link
Member

@jcfr jcfr commented Nov 6, 2025

AUTOMOC merges all moc_*.cpp into one Translation Unit (TU) (<target>_autogen/mocs_compilation*.cpp). For CTKDICOMWidgets, that TU ends up including both Python.h (via PythonQt) and DCMTK's osconfig.h. Across platforms, pyconfig.h and osconfig.h define overlapping HAVE_* feature macros; when merged, this yields widespread redefinition warnings.

On Windows, pyconfig.h may also typedef pid_t, colliding with DCMTK’s typedef and causing MSVC C2632 ("int followed by int is illegal"). On Unix-like systems, pid_t comes from <sys/types.h>, so the type clash does not escalate.

Fix:

  • Include PythonQtPythonInclude.h first in the generated wrapper header.
  • Immediately #undef a minimal set of Python-defined HAVE_* macros so DCMTK can (re)define them without conflict, restoring the effective isolation we had before enabling AUTOMOC.

Behavior is unchanged; this quiets warnings cross-platform and prevents the Windows build error.

…indows pid_t clash

AUTOMOC merges all `moc_*.cpp` into one Translation Unit (TU) (`<target>_autogen/mocs_compilation*.cpp`).
For CTKDICOMWidgets, that TU ends up including both `Python.h` (via PythonQt) and
DCMTK's osconfig.h. Across platforms, `pyconfig.h` and `osconfig.h` define overlapping
`HAVE_*` feature macros; when merged, this yields widespread redefinition warnings.

On Windows, `pyconfig.h` may also typedef `pid_t`, colliding with DCMTK’s typedef and
causing MSVC C2632 ("int followed by int is illegal"). On Unix-like systems,
`pid_t` comes from `<sys/types.h>`, so the type clash does not escalate.

Fix:
- Include `PythonQtPythonInclude.h` first in the generated wrapper header.
- Immediately `#undef` a minimal set of Python-defined `HAVE_*` macros so DCMTK can
  (re)define them without conflict, restoring the effective isolation we had before
  enabling AUTOMOC.

Behavior is unchanged; this quiets warnings cross-platform and prevents the
Windows build error.
@jcfr
Copy link
Member Author

jcfr commented Nov 6, 2025

This addresses the build error and warnings reported last night on CDash1

Error:

(compiling source file 'CTKDICOMWidgetsPythonQt_autogen/mocs_compilation_Release.cpp')
    C:\path\to\Slicer-build\DCMTK-build\config\include\dcmtk\config\osconfig.h(1083,9):
    see previous definition of 'HAVE_STRERROR'
C:\path\to\Slicer-build\python-install\include\pyconfig.h(225,13): error C2632: 'int' followed by 'int' is illegal

Warnings:

C:\path\to\Slicer-build\python-install\include\pyconfig.h(51,9): warning C4005: 'HAVE_IO_H': macro redefinition
(compiling source file 'CTKDICOMWidgetsPythonQt_autogen/mocs_compilation_Release.cpp')
    C:\path\to\Slicer-build\DCMTK-build\config\include\dcmtk\config\osconfig.h(179,9):
    see previous definition of 'HAVE_IO_H'
C:\path\to\Slicer-build\python-install\include\pyconfig.h(52,9): warning C4005: 'HAVE_SYS_UTIME_H': macro redefinition
(compiling source file 'CTKDICOMWidgetsPythonQt_autogen/mocs_compilation_Release.cpp')
    C:\path\to\Slicer-build\DCMTK-build\config\include\dcmtk\config\osconfig.h(446,9):
    see previous definition of 'HAVE_SYS_UTIME_H'
C:\path\to\Slicer-build\python-install\include\pyconfig.h(53,9): warning C4005: 'HAVE_TEMPNAM': macro redefinition
(compiling source file 'CTKDICOMWidgetsPythonQt_autogen/mocs_compilation_Release.cpp')
    C:\path\to\Slicer-build\DCMTK-build\config\include\dcmtk\config\osconfig.h(1088,9):
    see previous definition of 'HAVE_TEMPNAM'
C:\path\to\Slicer-build\python-install\include\pyconfig.h(55,9): warning C4005: 'HAVE_TMPNAM': macro redefinition
(compiling source file 'CTKDICOMWidgetsPythonQt_autogen/mocs_compilation_Release.cpp')
    C:\path\to\Slicer-build\DCMTK-build\config\include\dcmtk\config\osconfig.h(1090,9):
    see previous definition of 'HAVE_TMPNAM'
C:\path\to\Slicer-build\python-install\include\pyconfig.h(57,9): warning C4005: 'HAVE_STRERROR': macro redefinition
(compiling source file 'CTKDICOMWidgetsPythonQt_autogen/mocs_compilation_Release.cpp')
C:\path\to\Slicer-build\python-install\include\pyconfig.h(524,9): warning C4005: 'HAVE_FTIME': macro redefinition
(compiling source file 'CTKDICOMWidgetsPythonQt_autogen/mocs_compilation_Release.cpp')
    C:\path\to\Slicer-build\DCMTK-build\config\include\dcmtk\config\osconfig.h(114,9):
    see previous definition of 'HAVE_FTIME'
C:\path\to\Slicer-build\python-install\include\pyconfig.h(533,9): warning C4005: 'HAVE_GETPID': macro redefinition
(compiling source file 'CTKDICOMWidgetsPythonQt_autogen/mocs_compilation_Release.cpp')
    C:\path\to\Slicer-build\DCMTK-build\config\include\dcmtk\config\osconfig.h(144,9):
    see previous definition of 'HAVE_GETPID'


Since similar workaround have been implemented in other location in both CTK and Slicer, consolidation of those will be required and is tracked in those issues:


cc: @jamesobutler @ebrahimebrahim

Footnotes

  1. https://slicer.cdash.org/builds/3984970

@jcfr jcfr merged commit 4949c8e into commontk:master Nov 6, 2025
3 checks passed
@jcfr jcfr deleted the fix-automoc-mocs-dcmtk-python-macro-clash branch November 6, 2025 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant