[CMake] shared library linking question

Andreas Pakulat apaku at gmx.de
Sat Feb 13 03:34:48 EST 2010


On 13.02.10 00:35:17, Tim Blechmann wrote:
> hi all,
> 
> i am trying to write a cmake build system for an existing project and have 
> some troubles with linking of shared libraries.
> 
> basically, my directory layout of the targets is the following:
> 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. Additionally
in newer CMake versions cmake will set the RPATH of the target1/target2
binaries to point to the directory and changes this RPATH when installing
everything. Hence the loader should find your library. 

That doesn't work if you instead pass the libcommon.so as relative or
absolute path to target_link_libraries.

Andreas

-- 
You're ugly and your mother dresses you funny.


More information about the CMake mailing list