2

When I execute

gcc -H myfile.c 2>&1 > gcc.log

I get the following output on the screen:

. /usr/include/argp.h
.. /usr/include/stdio.h
... /usr/include/features.h
.... /usr/include/x86_64-linux-gnu/sys/cdefs.h
..... /usr/include/x86_64-linux-gnu/bits/wordsize.h
.... /usr/include/x86_64-linux-gnu/gnu/stubs.h
..... /usr/include/x86_64-linux-gnu/gnu/stubs-64.h
... /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
... /usr/include/x86_64-linux-gnu/bits/types.h
.... /usr/include/x86_64-linux-gnu/bits/wordsize.h
.... /usr/include/x86_64-linux-gnu/bits/typesizes.h
... /usr/include/libio.h
.... /usr/include/_G_config.h
..... /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
..... /usr/include/wchar.h
.... /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdarg.h
... /usr/include/x86_64-linux-gnu/bits/stdio_lim.h
... /usr/include/x86_64-linux-gnu/bits/sys_errlist.h
.. /usr/include/ctype.h
... /usr/include/endian.h
.... /usr/include/x86_64-linux-gnu/bits/endian.h
.... /usr/include/x86_64-linux-gnu/bits/byteswap.h
..... /usr/include/x86_64-linux-gnu/bits/wordsize.h
..... /usr/include/x86_64-linux-gnu/bits/byteswap-16.h
... /usr/include/xlocale.h
.. /usr/include/getopt.h
.. /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h
... /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/syslimits.h
.... /usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/limits.h
..... /usr/include/limits.h
...... /usr/include/x86_64-linux-gnu/bits/posix1_lim.h
....... /usr/include/x86_64-linux-gnu/bits/local_lim.h
........ /usr/include/linux/limits.h
...... /usr/include/x86_64-linux-gnu/bits/posix2_lim.h
.. /usr/include/errno.h
... /usr/include/x86_64-linux-gnu/bits/errno.h
.... /usr/include/linux/errno.h
..... /usr/include/x86_64-linux-gnu/asm/errno.h
...... /usr/include/asm-generic/errno.h
....... /usr/include/asm-generic/errno-base.h
. /usr/include/argz.h
.. /usr/include/errno.h
.. /usr/include/string.h
... /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
. /usr/include/stdlib.h
.. /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
.. /usr/include/x86_64-linux-gnu/bits/waitflags.h
.. /usr/include/x86_64-linux-gnu/bits/waitstatus.h
.. /usr/include/x86_64-linux-gnu/sys/types.h
... /usr/include/time.h
... /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
... /usr/include/x86_64-linux-gnu/sys/select.h
.... /usr/include/x86_64-linux-gnu/bits/select.h
..... /usr/include/x86_64-linux-gnu/bits/wordsize.h
.... /usr/include/x86_64-linux-gnu/bits/sigset.h
.... /usr/include/time.h
.... /usr/include/x86_64-linux-gnu/bits/time.h
... /usr/include/x86_64-linux-gnu/sys/sysmacros.h
... /usr/include/x86_64-linux-gnu/bits/pthreadtypes.h
.... /usr/include/x86_64-linux-gnu/bits/wordsize.h
.. /usr/include/alloca.h
... /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h
.. /usr/include/x86_64-linux-gnu/bits/stdlib-float.h
.. /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdbool.h
.. /usr/lib/gcc/x86_64-linux-gnu/4.8/include/stdint.h
... /usr/include/stdint.h
.... /usr/include/x86_64-linux-gnu/bits/wchar.h
.... /usr/include/x86_64-linux-gnu/bits/wordsize.h
Multiple include guards may be useful for:
/usr/include/limits.h
/usr/include/linux/errno.h
/usr/include/wchar.h
/usr/include/x86_64-linux-gnu/asm/errno.h
/usr/include/x86_64-linux-gnu/bits/byteswap-16.h
/usr/include/x86_64-linux-gnu/bits/byteswap.h
/usr/include/x86_64-linux-gnu/bits/endian.h
/usr/include/x86_64-linux-gnu/bits/errno.h
/usr/include/x86_64-linux-gnu/bits/local_lim.h
/usr/include/x86_64-linux-gnu/bits/select.h
/usr/include/x86_64-linux-gnu/bits/sigset.h
/usr/include/x86_64-linux-gnu/bits/stdio_lim.h
/usr/include/x86_64-linux-gnu/bits/stdlib-float.h
/usr/include/x86_64-linux-gnu/bits/sys_errlist.h
/usr/include/x86_64-linux-gnu/bits/time.h
/usr/include/x86_64-linux-gnu/bits/typesizes.h
/usr/include/x86_64-linux-gnu/bits/waitflags.h
/usr/include/x86_64-linux-gnu/bits/waitstatus.h
/usr/include/x86_64-linux-gnu/gnu/stubs-64.h
/usr/include/x86_64-linux-gnu/gnu/stubs.h
/usr/lib/gcc/x86_64-linux-gnu/4.8/include-fixed/syslimits.h

When I look into gcc.log, it is empty. What is going on? Why can I not capture the output of gcc -H?

What does the message Multiple include guards may be useful for: mean?

Any help is appreciated.

Jonny Henly
  • 4,023
  • 4
  • 26
  • 43
flashburn
  • 4,180
  • 7
  • 54
  • 109

2 Answers2

3

On OSX (which uses clang), gcc -H does write to stderr. However, your shell redirects stdin after it redirects stderr because it processes > gcc.log before 2>&1.

Instead, you can flip the order of the redirections:

$ gcc -H myfile.c > gcc.log 2>&1

This will first perform the redirection of stdin to gcc.log and then redirect stderr to stdin, which is now gcc.log.

Alternatively, you can be explicit with both:

$ gcc -H myfile.c > gcc.log 2> gcc.log

Rushy Panchal
  • 16,979
  • 16
  • 61
  • 94
  • What about the `Multiple include guards may be useful for:` in the output. What does it mean? – flashburn Jul 14 '16 at 22:00
  • @flashburn A "multiple include guard", as I know it, is a way of using `#define` and `#ifdef` to avoid including the same file multiple times, in case that has adverse behavior. That line might mean that those files are included multiple times and they should use the inclusion guards. However, I'm not too sure on that. See [this question](http://stackoverflow.com/questions/33768477/multiple-include-guards-may-be-useful-for-what-exactly) for a bit more information. – Rushy Panchal Jul 14 '16 at 22:12
  • 1
    In this case though, the "Multiple include guards" concerns itself with system headers, which you can't do anything about. If you open the /usr/include/limits.h file, it likely lacks an [include guard](https://en.wikipedia.org/wiki/Include_guard) – nos Jul 14 '16 at 22:26
2

You're doing the redirections in the wrong order, and AFAIK, you only need to redirect standard error as there's nothing on standard output.

$ gcc -H myFile.c 2>gcc.log

Doing 2>&1 before >gcc.log will first redirect standard error to the console (where standard output was going), then redirect standard output to the file.

Kusalananda
  • 14,885
  • 3
  • 41
  • 52