Order of link directories

Brad King brad.king at kitware.com
Mon Feb 5 15:26:04 CET 2007


David Faure wrote:
> On Friday 02 February 2007, Alexander Neundorf wrote:
>> On Friday 02 February 2007 21:46, David Faure wrote:
>>> What makes up the order of the link directories with cmake?
>>> `cmake --help-command link_directories` doesn't mention what happens when
>>> calling it multiple times, and I also don't know where builddir/lib gets
>>> added to the link directories.
>> As soon as you say 
>> target_link_libraries(someapp somelib)
>> and "somelib" is built in the same build, the directory where the library is 
>> created is added to the link path.
>> Finally there is some clever sorting algorithm in cmake which tries to get the 
>> order right.
> For some definition of clever, since it gets it wrong here ;)

It gets it right if you never use LINK_DIRECTORIES and just always give
the full path to all desired libraries.

>> Maybe the 
>> link_directories (${KDE4_LIB_DIR})
>> in the top level CMakeLists.txt isn't a good idea and should be removed. Can 
>> you please try that ?
> Indeed, it works!
> 
> I get this order now, though:
> -L/usr/local/lib -L/d/kde/build/4/kdepim/lib -L/d/kde/src/4/qt-copy/lib -L/usr/lib64 -L/d/kde/inst/kde4/lib
> This means that any kde stuff in /usr/lib64 (which is a symlink to /usr/lib) or in /usr/local/lib would
> be preferred over the kde prefix I'm compiling against (/d/kde/inst/kde4/lib). This could create trouble 
> with a kde4 installed by the distribution (not the case yet, but it will happen one day).
> 
> The correct order would be:
> -L/d/kde/build/4/kdepim/lib  (local stuff first)
> -L/d/kde/inst/kde4/lib    (the kde I'm compiling against)
> -L/d/kde/src/4/qt-copy/lib  (the qt I'm compiling against)
> -L/usr/lib64               (the system libs)
> [-L/usr/local/lib - not sure why we're automatically adding that one]

Given the full path to all desired libs, CMake actually inspects the
contents of all the directories.  A partial ordering of the link
directories is constructed.  It determines an order for the link
directories to make sure the linker will choose the correct copy of each
library.  If no such order exists a warning is issued.  The order on the
command line that you see will work unless new libs were installed
between running cmake and running make.

-Brad


More information about the Kde-buildsystem mailing list