[CMake] Library search path ordering

William A. Hoffman billlist at nycap.rr.com
Wed Aug 24 17:17:36 EDT 2005


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



More information about the CMake mailing list