0

Is it possible to write text into a file during compilation?

For example:

#ifdef ICC
#pragma write("log.txt", "ICC was used to compile %s", __FILE__)
function_optimized_for_icc()
#endif
Kadir
  • 1,345
  • 3
  • 15
  • 25
  • 1
    Don't see it for Visual Studio or gcc. gcc has `#pragma message string` though. https://gcc.gnu.org/onlinedocs/gcc/Diagnostic-Pragmas.html#Diagnostic-Pragmas. – R Sahu Jun 11 '14 at 06:41
  • 1
    http://stackoverflow.com/questions/3826832/is-there-a-portable-way-to-print-a-message-from-the-c-preprocessor – Retired Ninja Jun 11 '14 at 06:42
  • @RetiredNinja and @lserni, there are lots of different files to be compiled and there are lots of different compile flags for each compiler (`xlc`, `icc`, `gcc`). I wonder if there is a simple way to write the flags into a file. Redirecting compilation output and parsing it, is also a solution but it will be better if the parsing phase can be omitted. – Kadir Aug 19 '14 at 07:28

1 Answers1

2

Not that I know of, but in most compilers you can easily use a pragma to write a message to the console (#pragma warn, #pragma message etc.).

At that point you can just > redirect or tee the output to a file and filter it appropriately.

LSerni
  • 55,617
  • 10
  • 65
  • 107