2

In a project where the __FILE__ and __DATE__ macros are used in one of the modules, I am trying to redefine the values of these macros to explicit values during build time. Trying to use the -D option, like -D__TIME__=01:23:45 gave me a compilation error.

Compiling ./Console.c
In file included from <built-in>:324:
<command line>:41:9: error: redefining builtin macro [-Werror,-Wbuiltin-macro-redefined]
#define __TIME__ 01:23:45
        ^
1 error generated.

Is there a way to set these macros (and similar predefined macros) from the command line, w/o altering the source code itself?

ysap
  • 7,723
  • 7
  • 59
  • 122

1 Answers1

2

Compile with the switch -Wno-builtin-macro-redefined.

That will disable the warning (including the error you get because you are also compiling with -Werror). I cannot assure you what it will do with the macro definition—Clang appears to be obeying the request to use the command-line definition, but I do not know it will do so in all circumstances.

Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
  • GCC-5.4.0 also appears to obey the request as well. (Of course, one needs to use `'-D__TIME__="foo"' '-D__DATE__="bar"'`, as the macros should expand to a string literal.) – Nominal Animal Nov 07 '18 at 03:14