gpt4 book ai didi

c - 为什么我不能重定向 gcc -H 的输出

转载 作者:太空狗 更新时间:2023-10-29 11:36:02 37 4
gpt4 key购买 nike

当我执行

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: 是什么意思?

感谢任何帮助。

最佳答案

在 OSX(使用 clang)上,gcc -H 写入 stderr。但是,您的 shell 在重定向 stderr 之后重定向 stdin,因为它在 2>&1 之前处理 > gcc.log

相反,您可以翻转重定向的顺序:

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

这将首先执行 stdin 到 gcc.log 的重定向,然后将 stderr 重定向到 stdin,现在是 gcc.log

或者,您可以对两者都明确:

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

关于c - 为什么我不能重定向 gcc -H 的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38384814/

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com