kernel: Explicitly define the main prototype if C++
If the embedded application has a main(), Zephyr requires it to have a signature with C linkage (no C++ name mangling). Otherwise Zephyr's init will not call it, but will call the default weak stub. But, when building with clang/llvm, when we build calling the compiler with --frestanding (for ex if CONFIG_MINIMAL_LIBC is set), the compiler will mangle the main() symbol name. This is not incorrect behavior from the compiler, as, in principle, in a freestanding environment main() does not have a special meaning. gcc is still not mangling it when called with --frestanding. To avoid this issue, we define explicitly the main linkage as extern C, in a header the application will always include. Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
This commit is contained in:
parent
234fec579a
commit
5a07588ae4
|
@ -29,6 +29,11 @@ typedef union {
|
|||
void (*thepfunc)(void);
|
||||
} z_max_align_t;
|
||||
|
||||
#ifdef __cplusplus
|
||||
/* Zephyr requires an int main(void) signature with C linkage for the application main if present */
|
||||
extern int main(void);
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue