User forums > Using Code::Blocks
#defines and shell issue
xxxxviii:
Hi all,
Thank you for the replies. The back ticks worked on the #defines. Though under Windows I needed to do a bit of cludge to get the whole item in a string (used a GNU port of date).
So thank you.
Jenna:
--- Quote from: xxxxviii on April 17, 2015, 02:01:47 am ---Hi all,
Thank you for the replies. The back ticks worked on the #defines. Though under Windows I needed to do a bit of cludge to get the whole item in a string (used a GNU port of date).
So thank you.
--- End quote ---
Did you look into the link oBFusCATed has posted, specially: http://wiki.codeblocks.org/index.php?title=Variable_expansion#Time_and_date ?
xxxxviii:
Jens,
Yes, I did. What I did in the end was this:
On the defines page
Linux version
BUILD_DATE=`date -u +"%F"`
BUILD_TIME=`date -u +"%T"`
Windows version
BUILD_DATE=`F:\bin\gnudate.exe -u +"%F"`
BUILD_TIME=`F:\bin\gnudate.exe -u +"%T"`
in my main.cpp
#define xstr(s) #s
#define str(s) xstr(s)
#define BUILD_TIMESTAMP_ISO str(BUILD_DATE) "T" str(BUILD_TIME) "Z"
then later in the module as the report header:
fprintf(stdout, "%s (build %s %s)\n", MODULE_DESC, MODULE_VERSION, BUILD_TIMESTAMP_ISO);
which at execution prints something like:
SPDIAGNOSTIC (build 9.0.1 2015-04-17T05:20:03Z)
which is exactly what I was after.
M
P.S. reproducing from memory so please forgive any syntax mistake
oBFusCATed:
So we need a variable that returns the time only...
xxxxviii:
Not necessarily. The macros __DATE__ returns the compile date and __TIME__ the compile time. My issue (and I stress my issue) was I do not like the format returned. Turning it into an ISO format date YYYY-mmm-ddThh:mm:ssZ or YYYY-mm-ddThh:mm:ss+nnnn (for local time) is frustrating with the way the preprocessor works. It can be accomplished with around a page or so of code or shorter if you write a function that formats and returns a string.
The solution I have outlined works in three lines of source code and two define statements (could 'cheat' and use __TIME__ as this is the same as my second line).
The other frustration is producing a Windows version as Windows date is no where near as useful as the Linux date. Thankfully there was a GNU port with MinGW core utils (I could have written my own of course but time constrained).
It was just a matter of getting it in the right part of Code::Blocks.
M
Navigation
[0] Message Index
[*] Previous page
Go to full version