Skip to content

Commit 5a07588

Browse files
aescolarcarlescufi
authored andcommitted
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 <[email protected]>
1 parent 234fec5 commit 5a07588

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

include/zephyr/types.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ typedef union {
2929
void (*thepfunc)(void);
3030
} z_max_align_t;
3131

32+
#ifdef __cplusplus
33+
/* Zephyr requires an int main(void) signature with C linkage for the application main if present */
34+
extern int main(void);
35+
#endif
36+
3237
#ifdef __cplusplus
3338
}
3439
#endif

0 commit comments

Comments
 (0)