[CMake] Preserving library order in target_link_libraries(...) command

Brad King brad.king at kitware.com
Wed Nov 26 18:30:35 EST 2008


Bartlett, Roscoe A wrote:
> Does CMake guarantee that the order of the libraries passed into 
> target_link_libraries(...) is preserved on the actual link line?
>  
> For example, If I have:
>  
>     target_link_libraries(sometarget lib1 lib2 lib3 ...)
>  
> does CMake guarantee that the link line will have the ordering:
>  
>     g++  ... -llib1 -llib2 -llib3 ...
[snip]
> I am nervous to rely on the ordering that I am seeing without some 
> assurance that this ordering is guaranteed.

It is preserved for exactly your reason (unknown third-party 
inter-dependencies).  CMake might add libraries to the end of the list 
to satisfy known dependencies but always starts with the exact order 
(and multiplicity) provided by the user.

-Brad


More information about the CMake mailing list