[CMake] shared library linking question
Tim Blechmann
tim at klingt.org
Sat Feb 13 05:00:52 EST 2010
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?
> 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.
i am not completely fluent, how the linking process works. the rpath seems
to be set correctly, though. just the library is passed with a path relative
to the targets ...
thanks, tim
--
tim at klingt.org
http://tim.klingt.org
I don't write music for sissy ears.
Charles Ives
More information about the CMake
mailing list