[CMake] CMake removing duplicated static libraries from target_link_libraries list?

Michael Hertling mhertling at online.de
Wed Feb 2 10:13:05 EST 2011


On 02/02/2011 03:04 PM, Marco wrote:
> Hi all,
> 
> I'm wondering, if I understood correctly the behaviour of CMake, whether 
> there'a a way to prevent CMake from deleting duplicated libraries in a 
> target_link_libraries list.
> 
> I have an executable which links against (all static) libraries A, B and 
> C. A itself links against C,D,E... and so on. When CMake creates the 
> link.txt file what I see is:
> 
> c++ -o myExe -lA -lC -lD -lE -lB
> 
> that is cmake links the executable against A followed by its dependents, 
> then against B but not against C. The point is that B needs C to follow 
> it as B depends on C. This is why I suspect that CMake removes the 
> duplicated libraries listed in a target_link_libraries directive.
> 
> Is it correct? And is there a way to force CMake to preserve exactly the 
> list of libraries passed to target_link_libraries?

If B depends on C without C appearing after B in the link command, this
probably means that CMake isn't aware of the B-on-C dependency, so how
do you establish the latter? Could you provide a minimal but complete
example which demonstrates this issue?

AFAIK, CMake does not remove libraries from the link command if they
are necessary to resolve any dependencies and if these dependencies
are set up correctly, so the libraries' exact order - for library
targets - is nothing the user usually needs to worry about.

Regards,

Michael


More information about the CMake mailing list