Based on gcc: Do I need -D_REENTRANT with pthreads?
> echo | g++ -E -dM -c - > singlethreaded
> echo | g++ -pthread -E -dM -c - > multithreaded
> diff singlethreaded multithreaded
39a40
> #define _REENTRANT 1
The author uses the above command to export the options used by the compiler.
I want to know why such a command works in detail:
> echo | g++ -E -dM -c - > singlethreaded
I understand the following parts:
> singlethread # means to redirect the results to the file singlethread
The
-dMoption:The
-Eoption:The
-coption causes the compiler to compile but not link. This is superfluous with the -E option.The solitary
-tells the compiler to read its input from stdin.Thus, the command echoes an empty stream to
stdout, pipes that empty stream tog++, which then reads the empty stream but runs only the preprocessor, which has been told to ignore the input (empty) and output the complete list of defined preprocessor macros.