[CMake] Link something to future installed library
David Demelier
demelier.david at gmail.com
Sat Mar 23 12:37:56 EDT 2013
Le mercredi 13 mars 2013 11:35:13 Martin Koller a écrit :
> On Tuesday 12 March 2013 20:53:21 David Demelier wrote:
> > Thanks for your answer, however target_link_libraries() my modules to the
> > target of core will link to the build binary directory as expected :
> >
> > markand at Melon .../src/magicstat-2/_build_ $ ldd modules/battery/battery.so
> >
> > modules/battery/battery.so:
> > libcore.so =>
> >
> > /home/markand/work/src/magicstat-2/_build_/core/libcore.so (0x801204000)
> >
> > libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x801405000)
> > libm.so.5 => /lib/libm.so.5 (0x801715000)
> > libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x801936000)
> > libc.so.7 => /lib/libc.so.7 (0x80081a000)
> >
> > once installed..
> >
> > markand at Melon .../src/magicstat-2/_build_ $ ldd
> > /usr/local/lib/magicstat/modules/battery/battery.so
> >
> > /usr/local/lib/magicstat/modules/battery/battery.so:
> > libcore.so => not found (0)
> > libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x801204000)
> > libm.so.5 => /lib/libm.so.5 (0x801514000)
> > libgcc_s.so.1 => /lib/libgcc_s.so.1 (0x801735000)
> > libc.so.7 => /lib/libc.so.7 (0x80081a000)
>
> what you see is a different RPATH in the .so file.
> check this with "objdump -x yourfile.so | grep RPATH"
>
> To define a different RPATH on installed targets, use e.g.:
>
> set_target_properties(${target} PROPERTIES INSTALL_RPATH \$ORIGIN)
>
> (Where \$ORIGIN is a special keyword which is always relative to the
> directory the .so file is installed to. If you need different dirs, you can
> use other relative dirs, e.g.: "../../core" in your case (or similar - you
> get the picture). Check "man ld.so"
>
> > The installation hierarchy are the same as the build directory :
> >
> > build/core/libcore.so
> > build/modules/battery.so
> >
> > and /usr/local/lib/magicstat/libcore.so
> > /usr/local/lib/magicstat/modules/battery/battery.so
Hello,
Thanks for your answer and sorry for the late. I successfully managed to get
the runtime library working :-). However I needed to use a full path like
set_target_properties(mytarget PROPERTIES INSTALL_RPATH
"${CMAKE_INSTALL_PREFIX}/${PATH_MODULES}")
And did not managed to use relative links like "../../core", but there's no
problem. Thanks for your hint about ld.so, in fact I don't know really much
about dynamic libraries, it's such an obscure thing to me.
Regards,
--
David Demelier
More information about the CMake
mailing list