<div class="gmail_quote">On Sun, Aug 15, 2010 at 1:25 AM, Chris Wolf <span dir="ltr">&lt;<a href="mailto:cw10025@gmail.com">cw10025@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div><div></div><div class="h5"><br>
<br>
On 8/14/10 4:01 PM, Michael Wild wrote:<br>
&gt;<br>
&gt; On 14. Aug, 2010, at 18:26 , Chris Wolf wrote:<br>
&gt;<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt; On 8/14/10 10:31 AM, Michael Wild wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; On 14. Aug, 2010, at 15:13 , Chris Wolf wrote:<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; On 8/14/10 3:35 AM, Michael Wild wrote:<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; On 13. Aug, 2010, at 20:58 , Michael Wild wrote:<br>
&gt;&gt;&gt;&gt;&gt; [...]<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; Sure, <a href="http://repo.or.cz/w/freefoam.git/shortlog/refs/heads/pu" target="_blank">http://repo.or.cz/w/freefoam.git/shortlog/refs/heads/pu</a>, but it&#39;s pretty complex...<br>
&gt;&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt;&gt; Michael<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Attached is a tiny project which works for me on both Linux and Mac.<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;&gt; Michael<br>
&gt;&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; That&#39;s awesome! Thanks so much.  From your example, and looking at the documentation:<br>
&gt;&gt;&gt;&gt; <a href="http://www.cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH" target="_blank">http://www.cmake.org/Wiki/CMake_RPATH_handling#Always_full_RPATH</a><br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; ...I can see the difference now - you are setting CMAKE_INSTALL_NAME_DIR.<br>
&gt;&gt;&gt;&gt; (which is not needed or used on Linux/ELF)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; What I had been trying to do along these lines was a per-target setting:<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; set_target_properties(usbDynamic PROPERTIES INSTALL_NAME_DIR &quot;/tmp/local/lib&quot;)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; -=or=-<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; set_target_properties(usbDynamic PROPERTIES INSTALL_RPATH &quot;/tmp/local/lib/libusb-1.dylib&quot;&quot;)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; -=or=-<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; set_target_properties(usbDynamic PROPERTIES<br>
&gt;&gt;&gt;&gt;  INSTALL_RPATH &quot;/tmp/local/lib/libusb-1.dylib&quot;<br>
&gt;&gt;&gt;&gt;  INSTALL_NAME_DIR &quot;/tmp/local/lib&quot;)<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; None of those were working for me.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; I will incorporate your setting in my project.<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt; Thanks,<br>
&gt;&gt;&gt;&gt;<br>
&gt;&gt;&gt;&gt;  -Chris<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Aaaah, I see. The INSTALL_RPATH should have been /tmp/local/lib. And RPATH is only a Linux thing, while install_name is a Mac OS X thing ;-)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt; Michael<br>
&gt;&gt;<br>
&gt;&gt; Actually, &quot;/tmp/local/lib&quot; is just for testing - my intention is to use &quot;/usr/local/lib&quot;.<br>
&gt;&gt;<br>
&gt;&gt; Also RPATH on Mac OSX is no different then Linux, SunOS, etc. - only the mechanism to change it is.<br>
&gt;&gt;<br>
&gt;&gt; For example, CMake appears to use perform direct modification of ELF-formatted binaries,<br>
&gt;&gt; apparently to avoid relinking upon installation (i.e. running the generated cmake_install.cmake)<br>
&gt;&gt;<br>
&gt;&gt; It does this via the undocumented FILE(RPATH_CHANGE,.., FILE(RPATH_REMOVE,... routines.<br>
&gt;&gt; which are called indirectly via<br>
&gt;&gt; cmInstallTargetGenerator::PostReplacementTweaks/cmInstallTargetGenerator::AddChrpathPatchRule<br>
&gt;&gt;<br>
&gt;&gt; For some reason (maybe to accommodate frameworks) instead of polymorphically implementing<br>
&gt;&gt; cmSystemTools::ChangeRPath and cmSystemTools::RemoveRPath to handle the ELF *or* Darwin<br>
&gt;&gt; cases (which would have allowed AddChrpathPatchRule to work for ELF *and* Darwin)<br>
&gt;&gt; - a separate piece of logic was implemented for PostReplacementTweaks called,<br>
&gt;&gt; cmInstallTargetGenerator::AddInstallNamePatchRule, which invokes the OSX utility<br>
&gt;&gt; &quot;install_name_tool&quot; to change the RPATH in shared libraries and executables.<br>
&gt;&gt;<br>
&gt;&gt; The way I see it (and I could be wrong) there is divergence between the logic of<br>
&gt;&gt; AddChrpathPatchRule (ELF RPATH logic) and AddInstallNamePatchRule (Darwin RPATH logic)<br>
&gt;&gt;<br>
&gt;&gt; Ideally, if cmSystemTools::ChangeRPath and cmSystemTools::RemoveRPath  were<br>
&gt;&gt; polymorphic for ELF and Darwin, you would only need AddChrpathPatchRule and not<br>
&gt;&gt; AddInstallNamePatchRule, such that the FILE(RPATH_CHANGE,.., FILE(RPATH_REMOVE<br>
&gt;&gt; routines would function the same for ELF and Darwin and the generated<br>
&gt;&gt; &quot;cmake_install.cmake&quot; would look the same for both of these platforms - as a result,<br>
&gt;&gt; the documented behavior (<a href="http://www.cmake.org/Wiki/CMake_RPATH_handling" target="_blank">http://www.cmake.org/Wiki/CMake_RPATH_handling</a>)<br>
&gt;&gt; would be identical for ELF and Darwin cases.<br>
&gt;&gt;<br>
&gt;&gt; Well, that&#39;s my two cents...<br>
&gt;&gt;<br>
&gt;&gt; Thanks again for your help,<br>
&gt;&gt;<br>
&gt;&gt;  -Chris<br>
&gt;<br>
&gt; No, the two mechanisms are fundamentally different.<br>
&gt;<br>
&gt; On Linux the RPATH is a search path (think LD_LIBRARY_PATH) that is encoded into the binary. The linker<br>
&gt; only embeds the library name, no directory information. The loader then first searches these directories<br>
&gt; for the linked libraries, and then proceeds to search LD_LIBRARY_PATH and the directories defined in ld.conf.<br>
&gt;<br>
&gt; On Mac OS X, the install_name is a file name encoded into the library itself. When another binary is linked<br>
&gt; against this library, the linker hard-codes this file name into the binary, no matter what the actual location<br>
&gt; of the library is. The loader then tries to load that library using the hard-coded install_name from the binary,<br>
&gt; and only if that fails, uses DYLD_FALLBACK_LIBRARY_PATH.<br>
&gt;<br>
&gt; I hope this clarifies things a bit.<br>
&gt;<br>
&gt; Michael<br>
<br>
</div></div>Actually, I would say that the Darwin dynamic loader behavior is a super-set of the Linux dynamic loader.<br>
You can set RPATHs in an executable via the linker option &quot;-rpath /tmp/bar&quot; and instead of single<br>
colon-delimited path, you just specify multiple &quot;-rpath /some/path&quot; options.<br>
<br>
Then you can set the install_name on the dependent shared libraries to &quot;@rpath/mylib.dylib&quot; which is used<br>
to locate the shared library via the rpath(s) in the executable.  This would be the same behavior<br>
as Linux:<br>
<br>
See:   <a href="http://bit.ly/bNert1" target="_blank">http://bit.ly/bNert1</a><br>
       <a href="http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/dyld.1.html" target="_blank">http://developer.apple.com/mac/library/documentation/Darwin/Reference/ManPages/man1/dyld.1.html</a><br>

       <a href="http://bit.ly/csQGqb" target="_blank">http://bit.ly/csQGqb</a><br>
<br>
However, I am not necessarily advocating doing that, since that is not the convention used<br>
to deliver simple (i.e. not framework or bundle or plugins) apps and libraries.  All I am<br>
suggesting is that it might be helpful if CMake would present the same usage for specifying<br>
linkage behavior for Linux and Darwin, even if the underlying executable-&gt;library lookup<br>
mechanism is different.  Either that, or fix up the documentation to point out were things<br>
diverge.<br>
<font color="#888888"><br>
  -Chris<br>
</font><div><div></div><div class="h5"><br>
<br>
<br>
<br>
_______________________________________________<br>
Powered by <a href="http://www.kitware.com" target="_blank">www.kitware.com</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>
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>
Follow this link to subscribe/unsubscribe:<br>
<a href="http://www.cmake.org/mailman/listinfo/cmake" target="_blank">http://www.cmake.org/mailman/listinfo/cmake</a><br>
</div></div></blockquote></div><br><br>One thing that would be useful, for sure, for future googlers: a link from the Wiki articles on RPATH to this very email thread on the CMake mailing list...... Could somebody who knows where all those Wiki articles are add a link to this thread....??<br>
<br>Thanks,<br>David<br><br>