[CMake] MacOS and shared libraries from imported targets

Eric Doenges doenges at mvtec.com
Wed Sep 25 03:50:06 EDT 2019


As far as I am aware, the macOS linker simply records the install name 
of the dynamic library you link against in your executable (similar to 
how the Linux linker records the Elf SONAME, if present). So, the first 
step would be to check the install name of the external dynamic library 
by running 'otool -L' on it (the install name should be at the top of 
the output). You can change the install name using the install_name_tool 
(but if you build the external dynamic library yourself I think it is 
better to build the library with the correct install name in the first 
place).

Am 24.09.19 um 18:02 schrieb Michael Welsh Duggan:
> I have a project that links against an external dynamic library for
> which I have written a Find module that creates an import target.  I do
> this, in part, by setting the IMPORTED_LOCATION property of the target
> to the location of the dynamic library.
>
> Unfortunately, on OSX the library shows up in the executable load
> commands as an LC_LOAD_DYLIB of the raw filename (no directory) of the
> shared library.  I expected it to use the whole path.  I tried setting
> the INSTALL_NAME_DIR property to the directory containing the shared
> library, but this changed nothing.
>
> I will note that this is all still in the build location, as opposed to
> post-install.  I am using the following settings currently:
>
> set(CMAKE_SKIP_BUILD_RPATH false)
> set(CMAKE_BUILD_WITH_INSTALL_RPATH false)
> set(CMAKE_INSTALL_RPATH_USE_LINK_PATH true)
> set(CMAKE_MACOSX_RPATH true)
>
> I'm not 100% confident with how these options interact, so I am more
> than prepared for someone to tell me that I am doing something wrong.
> Any hints would be appreciated.
>
-- 

*Dr. Eric Dönges*
Senior Software Engineer

MVTec Software GmbH | Arnulfstr. 205 | 80634 Munich | Germany
doenges at mvtec.com <mailto:mustermann at mvtec.com> | Tel: +49 89 457 695-0 
| www.mvtec.com <http://www.mvtec.com>

Find our privacy policy here <https://www.mvtec.com/imprint>.

Sign up <https://www.mvtec.com/newsletter> for our MVTec Newsletter!

Geschäftsführer: Dr. Wolfgang Eckstein, Dr. Olaf Munkelt
Amtsgericht München HRB 114695

MVTec Software GmbH Logo
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cmake.org/pipermail/cmake/attachments/20190925/c6e08942/attachment-0001.html>


More information about the CMake mailing list