Closed fkjagodzinski closed 4 years ago
Could you please explain more (in the commit message) why including mbed.h
is needed?
What other ways are there to let GCC know that main()
is used and shouldn't be linked out?
What exactly is it about including the mbed.h
header file that causes -flto
to not remove the main()
function?
"Fix a missing header" <-- I believe this is not correct. If we don't use anything from mbed.h, why would it be considered "missing" if we don't have it?
Updated the commit message and PR description.
Fortunately, there is a better solution to undefined reference to 'main'
problem! Please see: https://github.com/ARMmbed/mbed-os/pull/11856#issuecomment-559097300
Add the "mbed.h" header to use the MBED_USED attribute with main().
Since the "used" attribute and the definition of main() have to be in the same translation unit, I placed a declaration of main() in "platform/mbed_toolchain.h" which "mbed.h" includes.
Without the attribute, the main() symbol is not emitted with the GCC toolchain using "-Wl,--wrap,main" and "-flto" flags.
This patch is required by https://github.com/ARMmbed/mbed-os/pull/11856.