[CMake] Linking to binary library with a relative path
GOO Creations
goocreations at gmail.com
Wed Mar 14 06:11:41 EDT 2012
Hi all,
I have a small problem linking a external library to my project. Here is
an indication of my directory structure.
root (dir)
|- external (dir)
|- external.so (shared library)
|- mylibs (dir)
|- <all my libraries>
|- myprog (executable)
In the directory "mylibs" all my source code is located. During
installation all the libraries are also stored in a dir "mylibs" (in the
install dir).
I then use Cmake to simply copy "external.so" to the install
directory. This library is already precompiled (binary). The executable
is linked to my libraries in the mylibs dir, and one lib in mylibs is
linked to external.so.
I use the following statements to link my libs:
ADD_LIBRARY(exter STATIC IMPORTED)
SET_TARGET_PROPERTIES(exter PROPERTIES IMPORTED_LOCATION
${CMAKE_INSTALL_PREFIX}/external/external.so)
TARGET_LINK_LIBRARIES(mylibx exter)
When I make and install the program, everything works perfectly, but
mylibx is linked to external.so via a absolute path (eg:
/home/me/project/install/external/external.so), hence when you rename
the install folder, the executable will complain that it can't find
external.so (since the absolute path was changed).
My first thought was to change the following
SET_TARGET_PROPERTIES(exter PROPERTIES IMPORTED_LOCATION
external/external.so)
Now I have a relative path, but during compilation mylibx throws an
error that it can't find external.so.
How can I tell Cmake to use the library external.so at a specific path,
but link mylibx to a relative path?
Thanks for any suggestions.
Christoph
More information about the CMake
mailing list