<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
        {font-family:Consolas;
        panose-1:2 11 6 9 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
p.msonormal0, li.msonormal0, div.msonormal0
        {mso-style-name:msonormal;
        mso-margin-top-alt:auto;
        margin-right:0in;
        mso-margin-bottom-alt:auto;
        margin-left:0in;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
span.gmail-pl-smi
        {mso-style-name:gmail-pl-smi;}
span.gmail-pl-s
        {mso-style-name:gmail-pl-s;}
span.gmail-pl-pds
        {mso-style-name:gmail-pl-pds;}
span.EmailStyle21
        {mso-style-type:personal-reply;
        font-family:"Calibri",sans-serif;
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-size:10.0pt;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang=EN-US link=blue vlink=purple><div class=WordSection1><p class=MsoNormal>On macOS you really should _<i>not</i>_ have to copy the libraries into the build tree. I have never had to do that in 10 years of our product (Windows is a different story). The trick is setting the correct options to add in the paths to the libraries into the RPATH of the executable/library. (at least on macOS & Linux systems).<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>--<o:p></o:p></p><p class=MsoNormal>Mike Jackson<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><div style='border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal><b><span style='font-size:12.0pt;color:black'>From: </span></b><span style='font-size:12.0pt;color:black'>Juan Sanchez <juan.e.sanchez@gmail.com><br><b>Date: </b>Thursday, September 12, 2019 at 11:35 AM<br><b>To: </b>Michael Jackson <mike.jackson@bluequartz.net><br><b>Cc: </b>CMake <cmake@cmake.org><br><b>Subject: </b>Re: [CMake] Setting RPATH lookup on macOS<o:p></o:p></span></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal>The macOS install_name_tool can be used to change the RPATH of your binaries.  It can also be used to set the path for each of the libraries to be loaded.  For a python module I compile, I copy each of its dylib into the appropriate directory relative to my shared library.  I then use the install_name_tool to change from an absolute path to a path relative to @loader_path.<o:p></o:p></p><div><p class=MsoNormal><o:p> </o:p></p></div><div><table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 style='border-collapse:collapse;box-sizing:border-box;border-spacing:0px'><tr style='box-sizing:border-box'><td style='padding:.75pt .75pt .75pt .75pt'></td></tr><tr style='box-sizing:border-box'><td valign=top style='padding:0in 7.5pt 0in 7.5pt;box-sizing:border-box;overflow:visible' id=gmail-LC65><p class=MsoNormal style='line-height:15.0pt'><span style='font-size:9.0pt;font-family:Consolas;color:#24292E'>install_name_tool -change <span class=gmail-pl-smi>$j</span> </span><span class=gmail-pl-pds><span style='font-size:9.0pt;font-family:Consolas;color:#032F62'>"</span></span><span class=gmail-pl-s><span style='font-size:9.0pt;font-family:Consolas;color:#032F62'>@loader_path/../gcc/</span></span><span class=gmail-pl-pds><span style='font-size:9.0pt;font-family:Consolas;color:#032F62'>`</span></span><span class=gmail-pl-s><span style='font-size:9.0pt;font-family:Consolas;color:#032F62'>basename </span></span><span class=gmail-pl-smi><span style='font-size:9.0pt;font-family:Consolas;color:#24292E'>$j</span></span><span class=gmail-pl-pds><span style='font-size:9.0pt;font-family:Consolas;color:#032F62'>`"</span></span><span style='font-size:9.0pt;font-family:Consolas;color:#24292E'> <span class=gmail-pl-smi>$i</span><o:p></o:p></span></p></td></tr><tr style='box-sizing:border-box'><td width=50 nowrap valign=top style='width:37.5pt;padding:0in 7.5pt 0in 7.5pt;box-sizing:border-box;min-width:50px;color:rgba(27,31,35,0.3)' id=gmail-L66></td></tr></table><p class=MsoNormal>where $j is the full path output from "otool -L" and "@loader_path/../gcc" would point to a directory "gcc" relative to the directory containing my python module.<br><br>For a binary executable, I would explore placing required dylib files into a directory relative to @executable_path.<br><br>Regards,<o:p></o:p></p></div><div><p class=MsoNormal><o:p> </o:p></p></div><div><p class=MsoNormal style='margin-bottom:12.0pt'>Juan<br><br><o:p></o:p></p></div></div><p class=MsoNormal><o:p> </o:p></p><div><div><p class=MsoNormal>On Wed, Sep 11, 2019 at 4:33 PM Michael Jackson <<a href="mailto:mike.jackson@bluequartz.net">mike.jackson@bluequartz.net</a>> wrote:<o:p></o:p></p></div><blockquote style='border:none;border-left:solid #CCCCCC 1.0pt;padding:0in 0in 0in 6.0pt;margin-left:4.8pt;margin-right:0in'><p class=MsoNormal>Already looked on google and at the CMake documentation but everything listed does not seem to work so here is the setup.<br><br>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. <br><br>Now I have my add_executable(foo…) and target_link_libraries (Foo ${MKL_LIBRARIES} ).<br><br>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.<br><br>639:[mjackson@ferb:ifort-release]$ otool -l Bin/EMsoftWorkbench.app/Contents/MacOS/EMsoftWorkbench | grep "path"<br>         name @rpath/libEbsdLib.dylib (offset 24)<br>         name @rpath/libmkl_rt.dylib (offset 24)<br>         name @rpath/QtOpenGL.framework/Versions/5/QtOpenGL (offset 24)<br>         name @rpath/QtNetwork.framework/Versions/5/QtNetwork (offset 24)<br>         name @rpath/QtConcurrent.framework/Versions/5/QtConcurrent (offset 24)<br>         name @rpath/QtWidgets.framework/Versions/5/QtWidgets (offset 24)<br>         name @rpath/QtGui.framework/Versions/5/QtGui (offset 24)<br>         name @rpath/QtCore.framework/Versions/5/QtCore (offset 24)<br>         path /Users/Shared/EMsoft_SDK-ifort/EbsdLib-0.1-Release/lib (offset 12)<br>         path /Users/Shared/EMsoft_SDK-ifort/Qt5.12.3/5.12.3/clang_64/lib (offset 12)<br><br><br>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.<br><br>Help....<br><br>--<br>Michael Jackson | Owner, President<br>      BlueQuartz Software<br>[e] <a href="mailto:mike.jackson@bluequartz.net" target="_blank">mike.jackson@bluequartz.net</a><br>[w] <a href="http://www.bluequartz.net" target="_blank">www.bluequartz.net</a> <<a href="http://www.bluequartz.net" target="_blank">http://www.bluequartz.net</a>><br><br><br>-- <br><br>Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</a><br><br>Please keep messages on-topic and check the CMake FAQ at: <a href="http://www.cmake.org/Wiki/CMake_FAQ" target="_blank">http://www.cmake.org/Wiki/CMake_FAQ</a><br><br>Kitware offers various services to support the CMake community. For more information on each offering, please visit:<br><br>CMake Support: <a href="http://cmake.org/cmake/help/support.html" target="_blank">http://cmake.org/cmake/help/support.html</a><br>CMake Consulting: <a href="http://cmake.org/cmake/help/consulting.html" target="_blank">http://cmake.org/cmake/help/consulting.html</a><br>CMake Training Courses: <a href="http://cmake.org/cmake/help/training.html" target="_blank">http://cmake.org/cmake/help/training.html</a><br><br>Visit other Kitware open-source projects at <a href="http://www.kitware.com/opensource/opensource.html" target="_blank">http://www.kitware.com/opensource/opensource.html</a><br><br>Follow this link to subscribe/unsubscribe:<br><a href="https://cmake.org/mailman/listinfo/cmake" target="_blank">https://cmake.org/mailman/listinfo/cmake</a><o:p></o:p></p></blockquote></div></div></body></html>