Sometimes I have ‘multiple definitions’ in my projects: this means that I have functions defined in one source files, and I need to ‘overwrite’ one or more with a version in another source file. For example I have a source file with utility functions (Utility.c), and I want to overwrite some of these functions with a different implementation in a different file (MyUtility.c). How can I do this?
Typically this is done with changing the link order: changing the order the linker ‘sees’ the object files while linking. Yes, this is possible with a pure make file approach where I have complete control. But not easily with an Eclipse build tools integration: the linker panels do not allow to change or affect the link order of files :-(.
Link Order Feature in CodeWarrior for MCU10.5
Well, only until I have realized that the Eclipse based CodeWarrior for MCU10.5 has this feature implemented: I can change the link order :-).
I can find this option in the linker settings as ‘Link Order’. Below is a screenshot for ARM GNU linker settings in CodeWarrior for MCU10.5:
If I enable that option, I can move up/down files in the order for the linker:
Placing a file above another one, means it takes precedence (priority). I remember it that way: The higher in the list, the higher the priority :-).
Error: Multiple Definitions
Having multiple definitions can end up in a ‘multiple definition of‘ error, like this one for ARM GNU linker:
The linker is right: I do have multiple definitions :-). So how to get rid of this? The answer is to add the
option to the ARM GNU Linker flags:
With this, the linker is happy :mrgreen:.
❗ There is just one (potential) issue: I see that the list of files is passed to the linker on the command line (and not in a separate argument file). This means that the current implementation might hit a wall if the command line length exceeds the limits of the host operating system (8196 characters for Windows as far as I can tell).
The new linker panels in CodeWarrior for MCU10.5 allow me to change and modify the link order. That way I have the possibility to overwrite functions or objects defined in other files.
Happy Link Ordering 🙂