Skip to content

COMP: Link the full Python library for wrapped modules where required - #74

Merged
pieper merged 1 commit into
Slicer:mainfrom
pieper:fix-linux-python-module-link
Aug 11, 2026
Merged

COMP: Link the full Python library for wrapped modules where required#74
pieper merged 1 commit into
Slicer:mainfrom
pieper:fix-linux-python-module-link

Conversation

@pieper

@pieper pieper commented Aug 10, 2026

Copy link
Copy Markdown
Member

cc @AlexyPellegrini

Problem

This is the root cause of the current Linux build breakage in Slicer (Slicer/Slicer#9348), which appeared after the SuperBuild vtkAddon bump.

c44ce00 ("COMP: Only search for Python3 Development.Module component") did three coupled things:

  1. switched find_package(Python3 COMPONENTS Development)Development.Module,
  2. removed set(VTK_WRAP_PYTHON_FIND_LIBS 1) in vtkMacroKitPythonWrap.cmake (so the "find the Python library" block in vtkWrapPython.cmake became dead and VTK_Python3_LIBRARIES is never set), and
  3. removed ${VTK_Python3_LIBRARIES} from both target_link_libraries calls for the wrapped module.

Development.Module provides only Python3::Module, which deliberately leaves the Python C-API symbols undefined for the host interpreter to supply. That is fine where the linker allows undefined symbols (on macOS, MODULE targets link with -undefined dynamic_lookup), but on Linux the wrapped modules are linked with -Wl,--no-undefined (vtk_undefined_symbols_allowed=FALSE) and must resolve the Python symbols at link time. The result is a link failure of every wrapped module:

vtkAddonMathUtilitiesPython.cxx: undefined reference to `PyTuple_Size'

Fix

Restore what the removed code provided, gated on VTK_UNDEFINED_SYMBOLS_ALLOWED: keep Development.Module where undefined symbols are allowed, otherwise require the full Development component and link Python3::Python. VTK_WRAP_PYTHON_FIND_LIBS is set again so the block runs, and VTK_Python3_LIBRARIES is re-added to the wrapped-module link line (both the VTK<8.90 and VTK>=8.90 paths).

@AlexyPellegrini — since the Development.Module switch was intentional, flagging in case you'd prefer instead to exempt the wrapped MODULE targets from -Wl,--no-undefined (the way VTK's own module wrapper does). This PR takes the more conservative "restore the prior linkage" route to unbreak the dashboards.

Testing

Reproduced and fixed on an Ubuntu 22.04 Slicer superbuild (Release, VTK 9.6, Python 3.12): without the change the inner build fails linking the wrapped Python modules; with it, the full application builds, packages, and runs off the build machine — the previously-failing classes (vtkAddonMathUtilities, vtkSegmentation, …) load, and inherited base-class methods (vtkOrientedGridTransform.SetDisplacementGridData) are present.

🤖 Generated with Claude Code

c44ce00 ("COMP: Only search for Python3 Development.Module component") switched
the wrapping to find only Python3 Development.Module, dropped
VTK_WRAP_PYTHON_FIND_LIBS, and removed VTK_Python3_LIBRARIES from the wrapped
module link line. Development.Module leaves the Python C-API symbols undefined
for the host interpreter to provide, which is fine where the linker allows
undefined symbols (macOS links MODULE targets with -undefined dynamic_lookup),
but on Linux the wrapped modules are linked with -Wl,--no-undefined and must
resolve the Python symbols at link time. The result is a link failure of every
wrapped Python module, e.g.:

  vtkAddonMathUtilitiesPython.cxx: undefined reference to `PyTuple_Size'

Restore the behavior the removed code provided, gated on
VTK_UNDEFINED_SYMBOLS_ALLOWED: keep Development.Module where undefined symbols
are allowed, otherwise require the full Development component and link
Python3::Python. VTK_WRAP_PYTHON_FIND_LIBS is set again so the block runs, and
VTK_Python3_LIBRARIES is re-added to the wrapped module link line.

Reproduced and fixed on an Ubuntu 22.04 Slicer superbuild: without the change
the inner build fails linking the wrapped modules; with it the full application
builds, packages, and runs (the wrapped classes, including inherited base-class
methods, work).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>

@sjh26 sjh26 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

lgtm

@pieper
pieper merged commit 3dc6d63 into Slicer:main Aug 11, 2026
1 check passed
@pieper
pieper deleted the fix-linux-python-module-link branch August 11, 2026 14:15
@AlexyPellegrini

AlexyPellegrini commented Aug 12, 2026

Copy link
Copy Markdown
Contributor

When building Python modules on Linux and Mac it is intended to not link the python lib as the symbols are expected to be provided by running interpreter. This think this will break SlicerCore. Edit: or maybe not, if VTK_UNDEFINED_SYMBOLS_ALLOWED is defined that should be enough for SlicerCore.

To fix the original issue, JCFR indicated that we must add an option to tell VTK to not do this link by default: #27 (comment)

Once this option is defined, the VTK::Python target will have the appropriate flags to prevent link errors.

@pieper

pieper commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

@AlexyPellegrini thanks for looking in to this. The current code works for both mac and linux for today's preview builds of Slicer so we don't want to regress. If you can suggest changes that work for your purposes and don't break Slicer that's good.

We discussed with @Thibault-Pelletier yesterday and people can stick to the earlier hash of vtkAddon if this new code is a problem for any projects.

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.

3 participants