How to store compilation date in the final binary file in order to read it by an external program?
I am trying to migrate a project from IAR to STM32CubeIDE. In this project, I have two lines of code in the main (as global variables) that store the compilation date in the final binary file. These two lines are the following:
char const compilation_date[] ={'<','c','>',__DATE__[0],__DATE__[1],__DATE__[2],__DATE__[3],__DATE__[4],__DATE__[5],__DATE__[6],__DATE__[7],__DATE__[8],__DATE__[9],__DATE__[10],'<','/','c','>'};
#pragma required=compilation_dateThe first line builds the compilation string date while the second tells to IAR compiler that, although the variable is not reference in the code, it must include it in the final binary.
To migrate it to STM32CubeIDE (that uses gcc compiler) I need to use __attribute__((used)) instead of #pragma required=compilation_date. So, the ported lines of code are
char const compilation_month[] __attribute__((used)) ={'<','c','>',__DATE__[0],__DATE__[1],__DATE__[2],__DATE__[3],__DATE__[4],__DATE__[5],__DATE__[6],__DATE__[7],__DATE__[8],__DATE__[9],__DATE__[10],'<','/','c','>'};The problem is that when I compile the program I get the following error:
../Core/Src/main.c: error: initializer element is not constantThe reason is that gcc expects that global variables store constant values instead of values determined in compilation time.
So, the question is: how can I store the compilation date in the final binary file?
P.S: My objective is that I could read the compilation date reading the binary (using windows or linux)
