<div dir="ltr">Hello,<div><br></div><div>I just tried to set the MACOSX_RPATH 1 in the top CMakeLists of MyLib, and when I now do otool -L libMyLib.dyld, I can indeed see @rpath/libMyLib.dyld.</div><div>However, my executable &quot;MyExample&quot; is still not able to find the library at runtime. When I do otool -L MyExample, I still have libMyLib.dyld, not @rpath/libMyLib.dyld.</div>
<div>And I have same error (Library not loaded, image not found) when trying to start the example.</div><div><br></div><div>Should I add something more (or remove something) from my CMakeLists example ? </div><div><br></div>
<div>I&#39;m sorry I&#39;m not really familiar with these mechanisms. </div><div><br></div><div>Thank you very much.</div><div>-Laurent</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Sep 4, 2013 at 11:30 AM, Laurent Chauvin <span dir="ltr">&lt;<a href="mailto:lchauvin@bwh.harvard.edu" target="_blank">lchauvin@bwh.harvard.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thank you very much for your answer.<div><br></div><div>I will try to use the MACOSX_RPATH.</div><div><br>
</div><div>However, I have some questions. As the flag suggests, it&#39;s only for mac. Is there anything similar for Linux (and eventually Windows systems) ? </div>
<div><br></div><div>Also, the problem to set the full path of the library is, if I compile on Windows the extension of library will be dll, on Mac it will be dyld, and .a on linux.</div><div>I could make a condition to set the extension at the end of the name of the library like libMyLib.(dll, dyld, a) but, I feel like it&#39;s not really a clean way to do it.</div>

<div><br></div><div>Is there a better way to do it ?</div><div><br></div><div>Thank you very much.</div><div>-Laurent</div><div><br></div></div><div class="gmail_extra"><div><div class="h5"><br><br><div class="gmail_quote">
On Wed, Sep 4, 2013 at 10:57 AM, Clinton Stimpson <span dir="ltr">&lt;<a href="mailto:clinton@elemtech.com" target="_blank">clinton@elemtech.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div>On Tuesday, September 03, 2013 09:47:45 PM Laurent Chauvin wrote:<br>
&gt; Hello everyone,<br>
&gt;<br>
&gt; I&#39;m working on a library, and I would like the users be able to create their<br>
&gt; own program and liking to my library (by specifying path in cmake).<br>
&gt;<br>
&gt; I created the library and an example to test it.<br>
&gt; Everything compiles.<br>
&gt;<br>
&gt; However, when I try to run my example I have this error:<br>
&gt; MyExample:<br>
&gt;       libMyLib.1.dylib (compatibility version 1.0.0, current version 1.0.0)<br>
&gt;       /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version<br>
&gt; 56.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current<br>
&gt; version 169.3.0)<br>
&gt;<br>
&gt; The problem is my example is not in the same directory as my library (not<br>
&gt; even in a subdirectory). And it seems it&#39;s linking to my library with a<br>
&gt; relative path.<br>
&gt;<br>
&gt; If I add the path of my library in DYLD_LIBRARY_PATH it works, but I would<br>
&gt; like the users to be able to compile and link straight forward.<br>
&gt;<br>
&gt; To link the library to my example I use find_package(MyLib REQUIRED) and<br>
&gt; include(${MyLib_USE_FILE}) which basically do a LINK_DIRECTORIES with the<br>
&gt; absolute path of the library.<br>
&gt;<br>
&gt; Then I do add_executable and target_link_libraries(MyExample<br>
&gt; ${MyLib_LIBRARIES})<br>
&gt;<br>
&gt; Compilation is working fine. There is these options:<br>
&gt;<br>
&gt; -L/Absolute/Path/To/MyLib -lMyLib<br>
&gt;<br>
&gt; But at runtime, library cannot be found.<br>
&gt;<br>
&gt; Would it be possible to put the full path of my library when linking in the<br>
&gt; CMakeLists ?<br>
&gt;<br>
<br>
</div></div>You should use the full path to the library instead of LINK_DIRECTORIES.<br>
Its easiest if you use install(EXPORT ...) to have CMake generate an export<br>
file for you that can be included by your FindMyLib.cmake file.<br>
That export file will use the full path, and include any other necessary<br>
information about the library.<br>
<br>
But to solve the problem of finding the library at runtime (specifying a full<br>
path won&#39;t solve it), CMake 2.8.12 has a new feature to address exactly that<br>
problem.  For details: <a href="http://www.kitware.com/blog/home/post/510" target="_blank">http://www.kitware.com/blog/home/post/510</a><br>
<br>
If you can use CMake 2.8.12, then you need to put<br>
 set(MACOSX_RPATH 1)<br>
in the CMakeLists.txt of MyLib.<br>
<br>
If the user is using 2.8.12, then any executable they compile with your<br>
library will be able to find the library, no matter where it is.<br>
<br>
By the way, 2.8.12 is in a release candidate stage right now, and right now<br>
would be a good time for you to test the new feature that is meant to solve<br>
your problem.<br>
<br>
Clint<br>
</blockquote></div><br><br clear="all"><div><br></div></div></div><span class="HOEnZb"><font color="#888888">-- <br><div dir="ltr"><div>Laurent Chauvin, MS</div><div>Surgical Navigation and Robotics Laboratory, Radiology Department</div>
<div>Brigham And Women&#39;s Hospital, Harvard Medical School<br>
</div><div><a href="http://wiki.ncigt.org/index.php/User:Lchauvin" target="_blank">http://wiki.ncigt.org/index.php/User:Lchauvin</a></div></div>
</font></span></div>
</blockquote></div><br><br clear="all"><div><br></div>-- <br><div dir="ltr"><div>Laurent Chauvin, MS</div><div>Surgical Navigation and Robotics Laboratory, Radiology Department</div><div>Brigham And Women&#39;s Hospital, Harvard Medical School<br>
</div><div><a href="http://wiki.ncigt.org/index.php/User:Lchauvin" target="_blank">http://wiki.ncigt.org/index.php/User:Lchauvin</a></div></div>
</div>