My project involves a set of plugin libraries.  Those libraries get loaded 
dynamically at runtime, e.g. by calling dlopen().  The user can install them to 
any location they want, so the directory won't necessarily be in the library 
path.  I can safely assume, though, that they'll all be in the same directory.

Sometimes, one plugin directly depends on another plugin, and uses symbols 
defined in it.  That means that when I dlopen() the first plugin, it needs to 
locate the second one (which is in the same directory) or loading will fail.

On Linux, this seems to "just work".  Presumably this is because the directory 
containing a library is one of the default locations searched for other 
libraries it depends on?

On Mac OS it doesn't work.  It can be made to work, though, by using 
install_name_tool to specify @loader_path as the location of the dependent 
library.  I'm trying to get my CMake script to do this.  I've added the 
following line:

INSTALL(CODE "EXECUTE_PROCESS(COMMAND install_name_tool -change 
libOpenMMOpenCL.dylib @loader_path/libOpenMMOpenCL.dylib 
${CMAKE_INSTALL_PREFIX}/lib/plugins/libOpenMMRPMDOpenCL.dylib)")

This appears to execute correctly.  To verify that it worked, I add the 
following line immediately after that:

INSTALL(CODE "EXECUTE_PROCESS(COMMAND otool -L 
${CMAKE_INSTALL_PREFIX}/lib/plugins/libOpenMMRPMDOpenCL.dylib)")

So I first run install_name_tool to edit the path in the library, then run 
otool to print out the changed path.  That verifies that yes, the library 
really does contain the right path.

But at some later point in the build process, it's getting changed back again.  
I don't know where or why, but once the build finishes running, otool shows 
that the @loader_path/ prefix has been removed again.  How can I prevent this 
from happening?

I haven't even begun looking into how to make things work on Windows, but if 
anyone has suggestions on that, I'll be very grateful for those too!

Peter 
--

Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to