This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Use of __DATE__ and __TIME__ in linker command file



Hi,

I would like to have the build/link date and time in my c code. When I use the __DATE__ and __TIME__ macro directly in the .c files I just get the compile date/time of this file. Since I want to get the compile date/time of the whole programm I thought about placing the __DATE__ and __TIME__ macros in the linker comand file.  I read in slau131j on page 172 that the linker provides these macros.

But when I place somting like this

compile_time = __TIME__;

in my .cmd file I get the error: #10104 undefined symbol "15:10:42" used in expression

where 15:10:42 was the actual time I tried to compile the project.

This is probably because  __TIME__ is a string literal and a linker symbol like my "compile_time" is a 32-bit unsigned integer.

Any ideas how I can solve this problem?

  • What do you want compile_time to be, a 32bit value of unix seconds since 1970? (will overflow in 2038,  unsigned 32-bit in 2106)
    Or the number of seconds since midnight just  using __TIME__ 
     
    Use it to set internal RTC?, compile time will be a few seconds behind as you click compile button and actual code loaded and started.

    You could precompile-decode the ascii to dec: ( the \ is continue on next line)

    #define myseconds (__TIME__[0]-48)*36000 + (__TIME__[1]-48)*3600 + (__TIME__[3]-48)*600 + \
                      (__TIME__[4]-48)*60 + (__TIME__[6]-48)*10 + (__TIME__[7]-48) 

  • No I don't want to use it to set the RTC. I want the date and time at compile time or actually at link time. I need this to extend the firmware version, in case someone makes changes in the firmware and forgets to increment the version number. Or to distinguish test version from each other.

**Attention** This is a public forum