执行时
gcc -H myfile.c 2>&1 > gcc.log
我在屏幕上看到以下输出:
. /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
当我查看gcc.log时,它是空的。到底是怎么回事?为什么我无法捕获gcc -H
的输出?
消息Multiple include guards may be useful for:
的含义是什么?
感谢任何帮助。
答案 0 :(得分:3)
在OSX上(使用clang
),gcc -H
写入stderr。但是,在重定向stderr之后,shell重定向stdin,因为它在> gcc.log
之前处理2>&1
。
相反,您可以翻转重定向的顺序:
$ gcc -H myfile.c > gcc.log 2>&1
这将首先执行stdin重定向到gcc.log
,然后将stderr重定向到stdin,现在是gcc.log
。
或者,您可以明确指出:
$ gcc -H myfile.c > gcc.log 2> gcc.log
答案 1 :(得分:2)
您正在以错误的顺序进行重定向,而AFAIK,您只需重定向标准错误,因为标准输出中没有任何内容。
$ gcc -H myFile.c 2>gcc.log
在2>&1
之前执行>gcc.log
将首先将标准错误重定向到控制台(标准输出的位置),然后将标准输出重定向到文件。