[CMake] shared library linking question

Andreas Pakulat apaku at gmx.de
Sat Feb 13 06:55:04 EST 2010


On 13.02.10 11:00:52, Tim Blechmann wrote:
> hi andreas,
> 
> >> common/libcommon.so
> >> target1/target1
> >> target2/target2
> >> 
> >> both target1 and target2 are linked with libcommon, both work fine in the
> >> build directory, the libraries are resolved correctly.
> >> 
> >> after installing them, they are formatted like:
> >> $PREFIX/lib/libcommon.so
> >> $PREFIX/bin/target1
> >> $PREFIX/bin/target2
> >> 
> >> now libcommon.so cannot be resolved, probably because the targets are
> >> linked with ../common/libcommon.so, so the loader cannot find the shared
> >> library. what is the best way to resolve this issue?
> > 
> > How did you write your cmake file? Usually you'd be using the libcommon
> > target name in target_link_libraries for target1 and target2.
> 
> in common/ i build libcommon
> add_library(libcommon SHARED ...)
> 
> in the target directories, i build the target:
> add_executable(targetX ...)
> target_link_libraries(targetX libcommon)
> 
> the targets are built with 
> -rdynamic -L../common ../common/libcommon.so Wl,-
> rpath,../common:/path/to/common
> 
> from my limited understanding of the linking process, it should link with 
> -lcommon instead of using ../common/libcommon.so, since the rpath is already 
> set to ../common. but how can i tell cmake to do this?

As far as I can see this is ok. At least its the same in the cmake
projects I'm using. The point is that cmake will change this rpath when
you run make install (provided you have used install( TARGETS)). It'll
then set the RPATH to the absolute path of the install location of
libcommon.so. The linking with ../common/libcommon.so is ok, cmake
prefers to pass in path+filename to ld instead of using and relying on
the right order of -L + -l.

Andreas

-- 
Your supervisor is thinking about you.


More information about the CMake mailing list