Skip to content

Set install RPATH on macOS so binaries find libopenscap#2348

Merged
Mab879 merged 1 commit intoOpenSCAP:mainfrom
edlitmus:macos-install-rpath
May 4, 2026
Merged

Set install RPATH on macOS so binaries find libopenscap#2348
Mab879 merged 1 commit intoOpenSCAP:mainfrom
edlitmus:macos-install-rpath

Conversation

@edlitmus
Copy link
Copy Markdown

@edlitmus edlitmus commented May 4, 2026

Summary

After make install on macOS, oscap referenced @rpath/libopenscap.<ver>.dylib but the binary had no LC_RPATH entries, so dyld failed at startup:

dyld[…]: Library not loaded: @rpath/libopenscap.33.dylib
  Referenced from: /usr/local/bin/oscap
  Reason: no LC_RPATH's found

The library was installed correctly to /usr/local/lib/libopenscap.33.dylib; the binary just had no way to locate it without DYLD_LIBRARY_PATH. CMake on macOS strips the build-tree RPATH at install time and provides nothing in its place unless CMAKE_INSTALL_RPATH is set.

This adds, inside the existing if(APPLE) block in the root CMakeLists.txt:

  • CMAKE_MACOSX_RPATH ON
  • CMAKE_INSTALL_NAME_DIR "@rpath"
  • CMAKE_INSTALL_RPATH "@loader_path/../lib;${CMAKE_INSTALL_PREFIX}/lib"

@loader_path/../lib keeps the install relocatable; the absolute prefix path is a fallback. Linux and Windows are unaffected — the block is APPLE-only.

This is a follow-on to the macOS/FreeBSD portability work in #2326.

Test plan

  • Configure + build cleanly on macOS (Apple Silicon, Homebrew toolchain)
  • Staged install (DESTDIR=… make install): otool -l .../bin/oscap shows both LC_RPATH entries (@loader_path/../lib and /usr/local/lib)
  • Real install to /usr/local: oscap --version and oscap xccdf generate report … run without DYLD_LIBRARY_PATH
  • Linux unaffected (block is gated on APPLE; no CMake variables Linux uses are touched)

No new automated test — existing CI (.github/workflows/) runs on Ubuntu and Fedora only, so an RPATH check wouldn't execute. The fix is verifiable manually with otool -l on macOS.

After `make install`, oscap referenced @rpath/libopenscap.<ver>.dylib but
had no LC_RPATH entries, so dyld failed with "no LC_RPATH's found" unless
DYLD_LIBRARY_PATH was set. Add CMAKE_INSTALL_RPATH (@loader_path/../lib
plus the absolute install prefix) and CMAKE_INSTALL_NAME_DIR=@rpath so
installed binaries resolve the dylib in-place and remain relocatable.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented May 4, 2026

Copy link
Copy Markdown
Member

@Mab879 Mab879 left a comment

Choose a reason for hiding this comment

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

Thanks!

The failure on rawhide will be fixed #2347.

@Mab879 Mab879 merged commit 3227434 into OpenSCAP:main May 4, 2026
20 of 21 checks passed
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.

3 participants