close
Skip to content

[stable-33.0] keep sync dylib install_name as @rpath through cmake --install#9848

Merged
i2h3 merged 1 commit into
stable-33.0from
backport/9844/stable-33.0
Apr 16, 2026
Merged

[stable-33.0] keep sync dylib install_name as @rpath through cmake --install#9848
i2h3 merged 1 commit into
stable-33.0from
backport/9844/stable-33.0

Conversation

@backportbot
Copy link
Copy Markdown

@backportbot backportbot Bot commented Apr 16, 2026

Backport of PR #9844

…stall

Fixes a dyld failure at launch ("Library not loaded:
.../build/macos-clang-arm64/lib/libnextcloudsync.0.dylib") that reliably
reproduced after any rebuild, incremental or clean.

Symptom
-------
/Applications/NextcloudDev.app crashes immediately on launch:

    dyld: Library not loaded:
      /Users/<user>/.../build/macos-clang-arm64/lib/libnextcloudsync.0.dylib
    Referenced from: .../NextcloudDev.app/Contents/MacOS/NextcloudDev
    Reason: tried: '.../build/macos-clang-arm64/lib/libnextcloudsync.0.dylib'
      (no such file)

otool confirms the installed binary carries an absolute reference to a
file nothing ever installs:

    $ otool -L /Applications/NextcloudDev.app/Contents/MacOS/NextcloudDev
    ...
    /Users/<user>/.../build/macos-clang-arm64/lib/libnextcloudsync.0.dylib

The dylibs actually live in Contents/MacOS (via `install(TARGETS)`) and
Contents/Frameworks (via macdeployqt), never under build/.../lib.

Cause
-----
Each build writes this into work/build/src/gui/cmake_install.cmake:

    install_name_tool \
      -change @rpath/libnextcloud_csync.0.dylib \
              /<prefix>/lib/libnextcloud_csync.0.dylib \
      -change @rpath/libnextcloudsync.0.dylib  \
              /<prefix>/lib/libnextcloudsync.0.dylib  \
      .../NextcloudDev.app/Contents/MacOS/NextcloudDev

CMake derives the replacement from each library target's install_name.
When INSTALL_NAME_DIR is unset, CMake defaults to
${CMAKE_INSTALL_PREFIX}/lib/libfoo.dylib regardless of where the target
is actually installed. The build-tree bundle in work/build/bin is fine
(macdeployqt keeps @rpath and adds @loader_path/../Frameworks to RPATH);
it is cmake --install that corrupts the references as it copies the
bundle into image-Debug-master and on to /Applications.

The previous BUILD_WITH_INSTALL_RPATH fix only suppressed RPATH churn,
not the install_name rewrite.

Why the first launch "worked" was situational -- a stale dylib left at
that path from a prior build, an older cached binary, or the install
step having aborted earlier. Every fresh cmake --install produces the
broken absolute reference; nothing makes it self-healing.

Fix
---
Set INSTALL_NAME_DIR "@rpath" on nextcloudsync and nextcloud_csync.
cmake --install now keeps the dylib install_name as
@rpath/libfoo.dylib, and the -change against the executable becomes a
no-op against its existing @rpath/... reference. The nextcloud
binary's @loader_path/../Frameworks rpath then resolves the dylibs
macdeployqt placed in Contents/Frameworks.

Signed-off-by: Iva Horn <iva.horn@nextcloud.com>
@backportbot backportbot Bot requested a review from Aiiaiiio as a code owner April 16, 2026 10:33
@backportbot backportbot Bot requested a review from i2h3 April 16, 2026 10:33
@backportbot backportbot Bot added bug os: 🍎 macOS Apple macOS, formerly also known as OS X 3. to review labels Apr 16, 2026
@backportbot backportbot Bot added this to the 33.0.3 milestone Apr 16, 2026
@i2h3 i2h3 merged commit 29f9771 into stable-33.0 Apr 16, 2026
15 checks passed
@i2h3 i2h3 deleted the backport/9844/stable-33.0 branch April 16, 2026 10:34
@sonarqubecloud
Copy link
Copy Markdown

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review bug os: 🍎 macOS Apple macOS, formerly also known as OS X

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant