0
votes

I faced a stack overflow problem in my STM32F4xx project. It came out that printf is the cause. FreeRTOS support suggests to use printf-stdarg.c instead. I have removed all stdio.h includes in my project. It complains of "incompatible implicit declaration of built-in function 'printf'" but compiles OK meaning the linker has used the built-in library.

My question is how to how to prevent linker (gcc) from using built-in printf/sprintf function.

1
How does that error mean it used the built-in library? - Scott Hunter
I am using SW4STM32 under eclipse. - alsaleem
it only uses the standard one cos you're not supplying an alternative - Chris Turner
You can include any header you want that defines int printf(const char *format, ...). - byxor
@Scott Hunter: it is not error. it is a warning only. - alsaleem

1 Answers

3
votes

If you linked printf-stdarg.c into your executable, then that function will be called instead of the system defined printf. The functions in standard library are weak symbols, which means you can define a function of the same name which will override the system function.

Removing #include <stdio.h> doesn't prevent the system library from being linked in. It just gets rid of the function prototypes your code needs.

Put the includes back in your code and link with printf-stdarg.c, and your code will use those functions.