User forums > Using Code::Blocks

#defines and shell issue

(1/2) > >>

xxxxviii:
Code::Blocks: SVN 10120
O/S: Ubuntu 12.04 x86_64

I can quite happily create, compile and run a command line program, so all good so far.

Then I decided I wanted to define a variable TIMESTAMP_ISO. So on the Project build options page, Compiler settings, #defines, I enter:

TIMESTAMP_ISO=$(shell date -u '"\"%Y-%m-%dT%H:%M:%SZ\""')

as per a post elsewhere. The problem when compiling:

date   No such file or directory

Excuse me? date is in /bin where it belongs. I can run from command line, I can run by going /bin/sh -c date

Seriously at a loss why this is not working. Help?

M

oBFusCATed:
Why do you think the #defines page support this format?
Have you inspected the full build log?
What does shell mean?

xxxxviii:
The example given in full was:

-DTIMESTAMP_ISO=$(shell date -u '"\"%Y-%m-%dT%H:%M:%SZ\""')

in a makefile.  The defines page I understand is the one to use to implement the equivalent preprocessor command.

The build log only gave the text back I posted previously. 

The program Environments lists shell as being /bin/sh -c

M

osdt:
C::B supports backticks to run external commands, something like ...


--- Code: ---TIMESTAMP_ISO=`date -u +"%Y-%m-%d %H:%M:%SZ"`
--- End code ---

within Compiler settings->#defines should work.

Note: C::B caches external commands and therefore the result will not change within the current session.

oBFusCATed:
In fact there are some time/date related variables that could be a bit more portable.
See here: http://wiki.codeblocks.org/index.php?title=Variable_expansion

Navigation

[0] Message Index

[#] Next page

Go to full version