Solving undefined symbol __main_stack_size__ in ChibiOS 3.x

So 15 März 2015
By Uli Köhler

In STM32

Problem:

When trying to compile ChibiOS 3.x you get one of these error messages during the linking stage:

undefined symbol `__main_stack_size__' referenced in expression
undefined symbol `__process_stack_size__' referenced in expression

Solution:

In constrast to ChibiOS 2.x, the ChibiOS 3.x linker scripts do not contain the stack size definitions. If you are using a custom build system, you need to add these linker flags, e.g. by setting the LDFLAGS environment variable:

-Wl,--defsym=__process_stack_size__=0x400 -Wl,--defsym=__main_stack_size__=0x400

The value 0x400 (1024) is the default makefile value in ChibiOS at the time of writing this. You can also use custom appropriate values if desired. It it likely that this is the reason that the externally-defined linker-variable based approach was chosen for ChibiOS 3.x in the first place.