I\'m creating a bare-metal application for the stm32f407 microcontroller, which has an ARM Cortex M4 core. As such, I\'m delivering the implementation of functions like
When ld
links against a library, it will only pick those functions which are required at that time (because of references to functions from translation units which have been linked in before). The linker will forget all other functions (and the library won't be considered later).
Therefore the linking order does matter. Normally you would link in your application object file (which references malloc
), then the standard library (which provides malloc
and in turn references _sbrk
), and then your (application) library which provides _sbrk
.
So linking should look like
arm-none-eabi-gcc ... -o out.elf startup.o main.o -lc -lm -lapp
with the _sbrk
function being provided by libapp
.
So the order of the objects to be linked does matter.
Update
As stated in one of the comments: If you add debug symbols using -g
during compilation, then you have to link against libg as well (-lg
).
arm-none-eabi-gcc ... -o out.elf startup.o main.o -lc -g -lm -lapp