[cmake-developers] Order of linking libraries

Brad King brad.king at kitware.com
Wed Jan 22 08:58:48 EST 2014

On 01/22/2014 06:52 AM, J Decker wrote:
> On Wed, Jan 22, 2014 at 2:31 AM, Marcin Maslany <marcinmaslany at gmail.com> wrote:
>> what's the order of linking libraries? Is it always deterministic? I know it
>> is possible to build dependency graph on libraries with cmake and find the
>> correct order with topological sorting (this might be the way you do it).

Yes, this is the way to do it.

>> I am just courius what is the reason of different order, even if I use the
>> same machine to build binary.

The order in which make chooses to build independent libraries
does not influence the order of their appearance on the link
line of consuming targets.

> It's in the same order as it is specified; if the same configuration
> options are used, it should be the same list always.

The implementation is here:


Read the giant comment at the top of the file to see how the ordering
algorithm works.  When it refers to the "user specified" order it
means the order in target_link_libraries calls.


More information about the cmake-developers mailing list