[CMake] Library search path ordering

David Flitney flitney at fmrib.ox.ac.uk
Thu Aug 25 07:34:54 EDT 2005


Bill,

Thanks for that. If I understand correctly, what you're implying here 
is that I'll need to use:

TARGET_LINK_LIBRARIES(Project ${Project_BINARY_DATA}/lib/libmiscmaths,a)

to force my preferred ordering? I hadn't realised this was 
possible/necessary. Previously with CMake 2.0.6 - and also with 2.2 on 
non MacOSX platforms - I got the correct ordering without this (just 
lucky?).

Okay, that appears to work. It does leave me a little confused as to 
why there is a need for a configuration time reordering. Surely the 
developer could do this work through the order in the CMakeLists.txt 
file? As appears to be the case with the INCLUDE_DIRECTORIES 
directives.

Thanks again,

Dave

On 24 Aug 2005, at 22:17, William A. Hoffman wrote:

> To try and use -L and to make sure that full paths to libraries 
> specified are
> used, cmake reorders paths using the following algorithm:
>
>
> /** \class cmOrderLinkDirectories
>  * \brief Compute the best -L path order
>  *
>  * This class computes the best order for -L paths.
>  * It tries to make sure full path specified libraries are
>  * used.  For example if you have /usr/mylib/libfoo.a on as
>  * a link library for a target, and you also have /usr/lib/libbar.a
>  * and you also have /usr/lib/libfoo.a, then you would
>  * want -L/usr/mylib -L/usr/lib to make sure the correct libfoo.a is
>  * found by the linker.  The algorithm is as follows:
>  * - foreach library create a vector of directories it exists in.
>  * - foreach directory create a vector of directories that must come
>  *   after it, put this in a map<dir, vector<dir>> mapping from a 
> directory
>  *   to the vector of directories that it must be before.
>  * - put all directories into a vector
>  * - sort the vector with a compare function CanBeBefore
>  *   CanBeBefore returns true if a directory is OK to be before
>  *   another directory.  This is determined by looking at the
>  *   map<dir vector<dir>> and seeing if d1 is in the vector for d2.
>
>
> Can you be more specific about all the full path libraries you are 
> using, and
> are there any warnings from cmake about not being able to come up with 
> a correct order?
>
> -Bill
>
>
> At 01:07 PM 8/24/2005, David Flitney wrote:
>> OS: MacOSX 10.3.9 (Panther)
>> CMake Version: 2.2-beta
>>
>> I'm having a problem with -L directives. They are being reordered 
>> (optimised :-) ?) such that I can't control which gets searched 
>> first, e.g., say I have a locally built library:
>>
>> ${Project_BINARY_DIR}/lib/libmiscmaths.a
>>
>> but also there is an older version in /usr/local/maths/lib then I 
>> can't ensure that my locally built one is linked against.
>>
>> I've tried:
>>
>> LINK_DIRECTORIES(${Project_BINARY_DIR}/lib /usr/local/maths/lib)
>> TARGET_LINK_LIBRARY(Project miscmaths)
>>
>> but this ordering isn't being obeyed.
>>
>> -- 
>> Cheers, Dave
>>
>> Dave Flitney, IT Manager
>> Oxford Centre for Functional MRI of the Brain
>> E:flitney at fmrib.ox.ac.uk W:+44-1865-222713 F:+44-1865-222717
>> URL: http://www.fmrib.ox.ac.uk/~flitney
>>
>> _______________________________________________
>> CMake mailing list
>> CMake at cmake.org
>> http://www.cmake.org/mailman/listinfo/cmake
>
>
-- 
Cheers, Dave

Dave Flitney, IT Manager
Oxford Centre for Functional MRI of the Brain
E:flitney at fmrib.ox.ac.uk W:+44-1865-222713 F:+44-1865-222717
URL: http://www.fmrib.ox.ac.uk/~flitney



More information about the CMake mailing list