<div dir="ltr">Thank you for you help Clint.<div><br></div><div>I actually relinked, but as you said I still had the LINK_DIRECTORIES.</div><div>However, if I remove it, I have a linking error telling me it cannot find the library.</div>
<div><br></div><div>Should I keep the library in Target_Link_Libraries, or with new flags, dependency will automatically find the library ?</div><div><br></div><div>Thank you.</div><div>-Laurent</div></div><div class="gmail_extra">
<br><br><div class="gmail_quote">On Wed, Sep 4, 2013 at 11:59 AM, Clinton Stimpson <span dir="ltr"><<a href="mailto:clinton@elemtech.com" target="_blank">clinton@elemtech.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">On Wednesday, September 04, 2013 11:53:45 AM Laurent Chauvin wrote:<br>
> Hello,<br>
><br>
> I just tried to set the MACOSX_RPATH 1 in the top CMakeLists of MyLib, and<br>
> when I now do otool -L libMyLib.dyld, I can indeed see @rpath/libMyLib.dyld.<br>
> However, my executable "MyExample" is still not able to find the library at<br>
> runtime. When I do otool -L MyExample, I still have libMyLib.dyld, not<br>
> @rpath/libMyLib.dyld.<br>
<br>
</div>Did you relink MyExamle against the new libMyLib.dylib? CMake doesn't modify<br>
the install names of libraries being linked against, so if otool -L MyExample<br>
still gives "libMyLib.dylib", I'm assuming you didn't relink it. Using a<br>
cmake generated export file would take care of setting up dependencies so the<br>
relink would happen simply by doing a make. If you use LINK_DIRECTORIES, you<br>
miss the relink dependency.<br>
<br>
Clint<br>
<div class="HOEnZb"><div class="h5"><br>
> And I have same error (Library not loaded, image not found) when trying to<br>
> start the example.<br>
><br>
> Should I add something more (or remove something) from my CMakeLists<br>
> example ?<br>
><br>
> I'm sorry I'm not really familiar with these mechanisms.<br>
><br>
> Thank you very much.<br>
> -Laurent<br>
><br>
><br>
> On Wed, Sep 4, 2013 at 11:30 AM, Laurent Chauvin<br>
><br>
> <<a href="mailto:lchauvin@bwh.harvard.edu">lchauvin@bwh.harvard.edu</a>>wrote:<br>
> > Thank you very much for your answer.<br>
> ><br>
> > I will try to use the MACOSX_RPATH.<br>
> ><br>
> > However, I have some questions. As the flag suggests, it's only for mac.<br>
> > Is there anything similar for Linux (and eventually Windows systems) ?<br>
> ><br>
> > Also, the problem to set the full path of the library is, if I compile on<br>
> > Windows the extension of library will be dll, on Mac it will be dyld, and<br>
> > .a on linux.<br>
> > I could make a condition to set the extension at the end of the name of<br>
> > the library like libMyLib.(dll, dyld, a) but, I feel like it's not really<br>
> > a<br>
> > clean way to do it.<br>
> ><br>
> > Is there a better way to do it ?<br>
> ><br>
> > Thank you very much.<br>
> > -Laurent<br>
> ><br>
> > On Wed, Sep 4, 2013 at 10:57 AM, Clinton Stimpson<br>
<<a href="mailto:clinton@elemtech.com">clinton@elemtech.com</a>>wrote:<br>
> >> On Tuesday, September 03, 2013 09:47:45 PM Laurent Chauvin wrote:<br>
> >> > Hello everyone,<br>
> >> ><br>
> >> > I'm working on a library, and I would like the users be able to create<br>
> >><br>
> >> their<br>
> >><br>
> >> > own program and liking to my library (by specifying path in cmake).<br>
> >> ><br>
> >> > I created the library and an example to test it.<br>
> >> > Everything compiles.<br>
> >> ><br>
> >> > However, when I try to run my example I have this error:<br>
> >> ><br>
> >> > MyExample:<br>
> >> > libMyLib.1.dylib (compatibility version 1.0.0, current version<br>
> >><br>
> >> 1.0.0)<br>
> >><br>
> >> > /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current<br>
> >><br>
> >> version<br>
> >><br>
> >> > 56.0.0) /usr/lib/libSystem.B.dylib (compatibility version 1.0.0,<br>
> >> > current<br>
> >> > version 169.3.0)<br>
> >> ><br>
> >> > The problem is my example is not in the same directory as my library<br>
> >><br>
> >> (not<br>
> >><br>
> >> > even in a subdirectory). And it seems it's linking to my library with a<br>
> >> > relative path.<br>
> >> ><br>
> >> > If I add the path of my library in DYLD_LIBRARY_PATH it works, but I<br>
> >><br>
> >> would<br>
> >><br>
> >> > like the users to be able to compile and link straight forward.<br>
> >> ><br>
> >> > To link the library to my example I use find_package(MyLib REQUIRED)<br>
> >> > and<br>
> >> > include(${MyLib_USE_FILE}) which basically do a LINK_DIRECTORIES with<br>
> >><br>
> >> the<br>
> >><br>
> >> > absolute path of the library.<br>
> >> ><br>
> >> > Then I do add_executable and target_link_libraries(MyExample<br>
> >> > ${MyLib_LIBRARIES})<br>
> >> ><br>
> >> > Compilation is working fine. There is these options:<br>
> >> ><br>
> >> > -L/Absolute/Path/To/MyLib -lMyLib<br>
> >> ><br>
> >> > But at runtime, library cannot be found.<br>
> >> ><br>
> >> > Would it be possible to put the full path of my library when linking in<br>
> >><br>
> >> the<br>
> >><br>
> >> > CMakeLists ?<br>
> >><br>
> >> 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<br>
> >> 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<br>
> >> full<br>
> >> path won't solve it), CMake 2.8.12 has a new feature to address exactly<br>
> >> 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>
> >><br>
> >> set(MACOSX_RPATH 1)<br>
> >><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<br>
> >> now<br>
> >> would be a good time for you to test the new feature that is meant to<br>
> >> solve<br>
> >> your problem.<br>
> >><br>
> >> Clint<br>
> ><br>
> > --<br>
> > Laurent Chauvin, MS<br>
> > Surgical Navigation and Robotics Laboratory, Radiology Department<br>
> > Brigham And Women's Hospital, Harvard Medical School<br>
> > <a href="http://wiki.ncigt.org/index.php/User:Lchauvin" target="_blank">http://wiki.ncigt.org/index.php/User:Lchauvin</a><br>
--<br>
</div></div><div class="HOEnZb"><div class="h5">Clinton Stimpson<br>
Elemental Technologies, Inc<br>
Computational Simulation Software, LLC<br>
<a href="http://www.csimsoft.com" target="_blank">www.csimsoft.com</a><br>
</div></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'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>