[CMake] Confusion with fixup_bundle(..) and RPATH on macOS
Elvis Stansvik
elvis.stansvik at orexplore.com
Wed May 24 09:44:22 EDT 2017
2017-05-24 15:23 GMT+02:00 Elvis Stansvik <elvis.stansvik at orexplore.com>:
> Hi all,
>
> My application consists of an executable (orexplore-insight) and two
> shared libraries (libinsightview and libinsightmodel).
>
> In addition to that, I'm linking against Qt 5.8.0, VTK 8.0.0.rc1, HDF5
> 1.8.18 and Qwt 6.1.2.
>
> My goal is to make a self-contained .app bundle (and eventually a .dmg).
>
> This is what otool -L looks like on my executable, when installed:
>
> Kevins-MacBook-Pro:build insight$ otool -L
> ~/Insight/insight-inst/orexplore-insight.app/Contents/MacOS/orexplore-insight
> /Users/insight/Insight/insight-inst/orexplore-insight.app/Contents/MacOS/orexplore-insight:
> @rpath/libinsightview.dylib (compatibility version 0.0.0,
> current version 0.0.0)
> @rpath/libinsightmodel.dylib (compatibility version 0.0.0,
> current version 0.0.0)
> @rpath/libhdf5.10.2.1.dylib (compatibility version 10.2.1,
> current version 1.8.18)
> @rpath/QtConcurrent.framework/Versions/5/QtConcurrent
> (compatibility version 5.8.0, current version 5.8.0)
> libvtkChartsCore-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkImagingStatistics-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> libvtkRenderingContextOpenGL2-8.0.1.dylib (compatibility
> version 1.0.0, current version 1.0.0)
> libvtkRenderingQt-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkGUISupportQt-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> @rpath/QtWidgets.framework/Versions/5/QtWidgets (compatibility
> version 5.8.0, current version 5.8.0)
> @rpath/QtGui.framework/Versions/5/QtGui (compatibility version
> 5.8.0, current version 5.8.0)
> @rpath/QtCore.framework/Versions/5/QtCore (compatibility
> version 5.8.0, current version 5.8.0)
> libvtkRenderingLabel-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkRenderingVolumeOpenGL2-8.0.1.dylib (compatibility
> version 1.0.0, current version 1.0.0)
> libvtkRenderingOpenGL2-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa
> (compatibility version 1.0.0, current version 22.0.0)
> libvtkImagingMath-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkglew-8.0.1.dylib (compatibility version 1.0.0, current
> version 1.0.0)
> libvtkViewsContext2D-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkRenderingContext2D-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> libvtkViewsCore-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkInteractionWidgets-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> libvtkInteractionStyle-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> libvtkRenderingAnnotation-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> libvtkRenderingFreeType-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> libvtkfreetype-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices
> (compatibility version 1.0.0, current version 48.0.0)
> /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices
> (compatibility version 1.0.0, current version 775.19.0)
> libvtkRenderingVolume-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> libvtkRenderingCore-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkFiltersSources-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkFiltersGeneral-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkFiltersCore-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkImagingCore-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkCommonExecutionModel-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> libvtkCommonDataModel-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> libvtkCommonTransforms-8.0.1.dylib (compatibility version
> 1.0.0, current version 1.0.0)
> libvtkCommonMisc-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkCommonMath-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtkCommonCore-8.0.1.dylib (compatibility version 1.0.0,
> current version 1.0.0)
> libvtksys-8.0.1.dylib (compatibility version 1.0.0, current
> version 1.0.0)
> libvtkzlib-8.0.1.dylib (compatibility version 1.0.0, current
> version 1.0.0)
> libqwt.6.dylib (compatibility version 6.1.0, current version 6.1.2)
> /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current
> version 307.5.0)
> /usr/lib/libSystem.B.dylib (compatibility version 1.0.0,
> current version 1238.50.2)
> Kevins-MacBook-Pro:build insight$
>
> So from this I can see that Qt and HDF5 install libraries with an
> "@rpath/..."-style install_name, while VTK and Qwt does not (they use
> a filename-only install_name).
>
> So far so good I suppose.
>
> If I understand correctly, to make my application work as a
> self-containing .app bundle in this scenario, I must:
>
> 1. Bundle all dependent frameworks/libraries inside the .app (of course)
>
> 2. Ensure my executable has an LC_RPATH pointing to
> @executable_path/.., @executable_path/../Frameworks et.c., which makes
> sure the bundled libraries with "@rpath/..."-style install_names are
> found correctly.
>
> 3. Ensure my app is started with DYLD_LIBRARY_PATH pointing to
> wherever I bundle the libraries that do not use "@rpath/..."-style
> install_name's, so that they are found as well.
>
> Does this sound about right?
>
> Now on to my current problem:
>
> I can make sure my installed executable has e.g. an
> @executable_path/../Frameworks LC_RPATH by setting the INSTALL_RPATH
> target property. I've verified with otool -l on the installed
> executable that this is working. E.g:
>
> Load command 59
> cmd LC_RPATH
> cmdsize 48
> path @executable_path/../Frameworks (offset 12)
>
> However, if I try to make the bundle self-containing with
> fixup_bundle(...) from BundleUtilities, using an install snippet like:
>
> fixup_bundle("${CMAKE_INSTALL_PREFIX}/orexplore-insight.app" "" "")
>
> (the above is from an install(SCRIPT ...) of mine), then I get
> warnings and errors during `make install`, such as:
>
> warning: cannot resolve item '@rpath/libhdf5.10.2.1.dylib'
>
> and
>
> warning: target '@rpath/libhdf5.10.2.1.dylib' is not absolute...
>
> and
>
> warning: target '@rpath/libhdf5.10.2.1.dylib' does not exist...
>
> and
>
> warning: unexpected reference to '@rpath/libhdf5.10.2.1.dylib'
>
> And none of the libraries have been copied into the bundle.
Note also that the two libraries that _don't_ use @rpath install_name
(VTK and Qwt) are not found/copied either. So I'm not sure my issue is
related to @rpath at all.
As a test, I've also tried passing in the path to the VTK library
directory to the dirs parameter of fixup_bundle(..):
fixup_bundle("${CMAKE_INSTALL_PREFIX}/orexplore-insight.app" ""
"/Users/insight/Insight/VTK-8.0.0.rc1-inst/lib")
but the problem is the same. The libraries are not found, and I'm
getting warnings like:
warning: cannot resolve item 'libvtkFiltersCore-8.0.1.dylib'
possible problems:
need more directories?
need to use InstallRequiredSystemLibraries?
run in install tree instead of build tree?
and:
warning: target 'libvtkFiltersCore-8.0.1.dylib' is not absolute...
warning: target 'libvtkFiltersCore-8.0.1.dylib' does not exist...
And the library is not copied.
Elvis
>
> Furthermore, and what surprises me, is that after this failed install,
> if I look at the installed executable again with otool -l, then it
> seems fixup_bundle has removed the LC_RPATH :(
>
> I'm attaching the full output from `make install`. You can ignore that
> the installed paths of my own libraries (libinsightview and
> libinsightmodel) are a bit wrong, I'll fix that and I'm focusing on
> the third party libs for now.
>
> My questions are:
>
> 1. Anyone know what is going wrong with the fixup_bundle(...) here?
> Why can't it bundle the libraries? I've tried adding the directories
> of the third party libraries to DYLD_LIBRARY_PATH during the `make
> install`, to help fixup_bundle(...) find them, but it didn't make any
> difference.
>
> 2. Why is fixup_bundle(...) stripping out the LC_RPATH I added by
> means of setting the INSTALL_RPATH target property? I want that
> LC_RPATH to be there, so that bundled libraries with @rpath are found.
>
> Many thanks in advance,
> A confused Elvis
More information about the CMake
mailing list