Implicit function declarations

Hi,
I’m developing an application in C using the ST STM32 platform (15.4.0) and every other time I’m compiling, I see a number of ‘implicit declaration of function’ compiler warnings:

Building in release mode
Compiling .pio\build\nucleo_f072rb\src\ltb_eeprom.o
src\ltb_eeprom.c: In function 'ltbEEPROMInitialize':
src\ltb_eeprom.c:56:5: warning: implicit declaration of function 'MX_I2C2_Init'; did you mean 'HAL_I2C_Init'? [-Wimplicit-function-declaration]
     MX_I2C2_Init();
     ^~~~~~~~~~~~
     HAL_I2C_Init

the functions are defined, the linker can link the executable just fine and the application works as expected. But these warnings clutter the output and could lead to me overlooking an actual implicit function declaration. The warnings seem to appear only with HAL functions generated by STM32CubeMX’s code generator. Also, I don’t see the same warnings every time, sometimes its just one warning, other times its 5+ different warnings.
Does anyone know how these warnings can be fixed (or suppressed for HAL functions only)?

the issue seems to have been caused by missing includes. I included the HAL header files in the headers of the .c files where the warnings appeared, which has fixed the issue.
I was expecting the compiler to throw errors on missing includes.

1 Like

This file is STM32Cube defined? Never seen it generate a file like that. Looks to me like the compiler is right and you’re missing an include that has a

void MX_I2C2_Init();

declaration of the function.

that source file is one of mine.
in this specific case I fixed the warning by adding #include <i2c.h> to the header file. i2c.h is a file generated by STM32CubeMX but not included in main.h by default.