[CMake] Simple (?) problem with libraries & executable dependencies

Michael Hertling mhertling at online.de
Sun Feb 13 20:26:11 EST 2011


On 02/14/2011 01:32 AM, Carminati Federico wrote:
> Hello,
>    I have a problem with the dependencies of an executable. The executable depends on a number of shared libraries. If I define the executable like this
> 
> 
> add_executable(aliroot aliroot.cxx)
> target_link_libraries(aliroot Mylib)
> 
> then the link command really looks like
> 
> g++ -o aliroot ../lib/libMylib.so
> 
> and I have plenty of problems with relocation and rpaths. [...]

Which problems do you have exactly? Could you post an excerpt from the
output of "make VERBOSE=1" that shows the issue in more detail? Have
you already read [1]? How is the target "Mylib" defined?

> [...] If I just do
> 
> target_link_libraries(aliroot -lMylib)
> 
> the link command looks "right":
> 
> g++ -o aliroot -lMylib
> 
> however the executable is NOT relinked in case a library is recreated. [...]

No, this isn't right, not really. Besides other things - linker search
paths [2], selection of static/shared libraries [3] - the "-lMylib" is
taken verbatim and CMake does not recognize that you're aiming at your
project's Mylib target. So, the dependency of aliroot on Mylib doesn't
hold anymore and the executable isn't relinked when the library has
been rebuilt.

> [...] I even tried to do 
> 
> add_dependencies(aliroot <path to the library>/libMylib.so)
> 
> but it does not work. [...]

ADD_DEPENDENCIES() only works on targets, not on files.

> [...] Any hint? Thanks!

[1] http://www.cmake.org/Wiki/CMake_RPATH_handling
[2] http://www.cmake.org/pipermail/cmake/2011-January/041647.html
[3] http://www.cmake.org/Wiki/CMake_2.6_Notes#Link_Line_Generation

Regards,

Michael


More information about the CMake mailing list