Skip to content

BUG: Give the installed itkTestDriver an RPATH to ITK's libraries - #6894

Merged
hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:testdriver-install-rpath
Sep 26, 2026
Merged

hjmjohnson merged 1 commit into
InsightSoftwareConsortium:mainfrom
hjmjohnson:testdriver-install-rpath

Conversation

@hjmjohnson

@hjmjohnson hjmjohnson commented Sep 22, 2026 •

Copy link
Copy Markdown
Member

Give the installed itkTestDriver an install RPATH pointing at ITK's library directory, so it can load @rpath/libITKTestKernel (and the rest) from an install prefix without DYLD_LIBRARY_PATH / LD_LIBRARY_PATH.

Symptom and verification

Every external-module test that runs through ITK_TEST_DRIVER against an installed ITK aborts on macOS before running:

dyld: Library not loaded: @rpath/libITKTestKernel-6.0.1.dylib
  Referenced from: <prefix>/bin/itkTestDriver
  Reason: no LC_RPATH's found

ITK installs its libraries with @rpath install names but sets no INSTALL_RPATH anywhere, so the driver has no search path. Found while running remote-module test suites against an installed ITK for #6891.

With this change the installed driver carries LC_RPATH @loader_path/../lib ($ORIGIN/../lib on Linux), and LesionSizingToolkit's five ITK_TEST_DRIVER tests that aborted now pass from the installed prefix with no environment variables set.

Measured on a shared Release build installed to a scratch prefix, configured with -DCMAKE_INSTALL_RPATH=/opt/external/lib to confirm an externally supplied entry survives:

$ otool -l <prefix>/bin/itkTestDriver | grep -A2 LC_RPATH
    path /opt/external/lib
    path @loader_path/../lib
$ env -u DYLD_LIBRARY_PATH <prefix>/bin/itkTestDriver --no-process ; echo $?
0

DYLD_PRINT_LIBRARIES shows all 47 ITK libraries resolving from the prefix with no library-path variable set.

Install layouts

The RPATH is computed from ITK_INSTALL_RUNTIME_DIR and ITK_INSTALL_LIBRARY_DIR, so relative non-default layouts (lib64, a custom bin) resolve correctly.

Both variables are assumed relative to CMAKE_INSTALL_PREFIX, as they already are at CMake/ITKModuleMacros.cmake:533 and :542. An absolute value is rejected at configure time, because by that point the install tree is already wrong. With -DCMAKE_INSTALL_LIBDIR=/usr/lib64 on main today, the exported configuration gets

ITKCommon_RUNTIME_LIBRARY_DIRS = "<build-dir>//usr/lib64"

which is the build directory joined to the absolute path, pointing where nothing is installed; CMake also writes the generated package files into <build-dir>/usr/lib64/. That configuration is broken rather than merely unsupported, so failing early beats shipping an install tree whose exported paths do not exist. Making ITK handle absolute install directories properly spans the module macros and the exported configuration and is tracked separately in #6896.

@github-actions github-actions Bot added type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots area:Core Issues affecting the Core module labels Sep 22, 2026
@hjmjohnson
hjmjohnson marked this pull request as ready for review September 22, 2026 22:12
@greptile-apps

This comment has been minimized.

Comment thread Modules/Core/TestKernel/src/CMakeLists.txt Outdated
Comment thread Modules/Core/TestKernel/src/CMakeLists.txt Outdated
@greptile-apps

This comment has been minimized.

@hjmjohnson

Copy link
Copy Markdown
Member Author

Two force-pushes just landed: the first (e26302bb0f4 → b9b00a57974) is the review fixes only, on the original base; the second (b9b00a57974 → dd1e9d70d65) is a plain rebase on main with no content change (git range-diff reports =).

ITK's libraries are installed with @rpath install names, but the installed
itkTestDriver carries no RPATH, so on macOS it fails to load
libITKTestKernel from <prefix>/lib and every external module test that runs
through ITK_TEST_DRIVER aborts unless DYLD_LIBRARY_PATH is set. Set the
install RPATH to the library directory relative to the runtime directory,
which also covers Linux installs that do not add <prefix>/lib to the loader
path.
@hjmjohnson
hjmjohnson force-pushed the testdriver-install-rpath branch from dd1e9d7 to 936d538 Compare September 23, 2026 11:10

@dzenanz dzenanz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, but my primary dev OS is Windows, so it would good if someone else reviewed this too.

@hjmjohnson
hjmjohnson merged commit a899196 into InsightSoftwareConsortium:main Sep 26, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:Core Issues affecting the Core module type:Bug Inconsistencies or issues which will cause an incorrect result under some or all circumstances type:Infrastructure Infrastructure/ecosystem related changes, such as CMake or buildbots

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants