is there any way to change the linking order in cmake?

How to change CMake linking order?

As far as the linking order of sources of a target is concerned, try reordering the arguments.

As for the linking order of libraries, you can use target_link_options with SHELL:.

Is this a documented feature?

No.

can I rely on this behaviour?

Generally yes, I never seen cmake reordering object files.

The embedded systems domain is plagued with __weak function redefinition

I would disagree.

Why link order is important to me

The link order of object files is irrelevant – all symbols are loaded at one pass. What is causing problems with weak symbols is the linking order of static libraries. In modern cmake use OBJECT libraries, in older cmake use --whole-archive linker flag. When using whole-archive, be aware of LINK_INTERFACE_MULTIPLICITY.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top