[CMake] Setting RPATH lookup on macOS

Michael Jackson mike.jackson at bluequartz.net
Wed Sep 11 17:33:46 EDT 2019


Already looked on google and at the CMake documentation but everything listed does not seem to work so here is the setup.

I am using MKL and I have a home grown FindMKL since there isn’t an official one. Inside that is the typical find_library() calls which will find the libraries just fine. One of those libraries is a dynamic library (.dylib). Using otool -L on that library the install_name is encoded as @rpath. 

Now I have my add_executable(foo…) and target_link_libraries (Foo ${MKL_LIBRARIES} ).

Everything compiles and links fine. The issue is at runtime. The app will not launch because libmkl_rt.dylib is not loaded because the path to that library is not encoded into the executable.

639:[mjackson at ferb:ifort-release]$ otool -l Bin/EMsoftWorkbench.app/Contents/MacOS/EMsoftWorkbench | grep "path"
         name @rpath/libEbsdLib.dylib (offset 24)
         name @rpath/libmkl_rt.dylib (offset 24)
         name @rpath/QtOpenGL.framework/Versions/5/QtOpenGL (offset 24)
         name @rpath/QtNetwork.framework/Versions/5/QtNetwork (offset 24)
         name @rpath/QtConcurrent.framework/Versions/5/QtConcurrent (offset 24)
         name @rpath/QtWidgets.framework/Versions/5/QtWidgets (offset 24)
         name @rpath/QtGui.framework/Versions/5/QtGui (offset 24)
         name @rpath/QtCore.framework/Versions/5/QtCore (offset 24)
         path /Users/Shared/EMsoft_SDK-ifort/EbsdLib-0.1-Release/lib (offset 12)
         path /Users/Shared/EMsoft_SDK-ifort/Qt5.12.3/5.12.3/clang_64/lib (offset 12)


Oddly the Qt libraries and one of my own libraries do get their rpaths encoded. I feel like I need to append to the RPATH that gets encoded into the executable but I am not really figuring out how to do that.

Help....

--
Michael Jackson | Owner, President
      BlueQuartz Software
[e] mike.jackson at bluequartz.net
[w] www.bluequartz.net <http://www.bluequartz.net>




More information about the CMake mailing list