微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

我如何在Linux中findC编程语言的头文件?

当我在Linux中编写C程序,然后使用gcc进行编译时,我总是对这些头文件的位置感到好奇。 例如,在哪里stdio.h是。 更一般地说, stdbool.h在哪里?

我想知道的不仅仅是它在哪里,而且也是如何获得这些地方,例如,使用shell命令或使用C编程语言。

我在哪里可以findunix上的C头文件

sspI头文件 – 致命错误

我在哪里可以下载用于Windows的Python 2.7.3的开发标题

Ubuntu中的skbuff.h文件在哪里?

文件顺序

gcc -H ...将打印每个包含文件的完整路径作为定期编译的副作用。 除了使用-fSyntax-only之外,不要创建任何输出(它仍会告诉你,如果你的程序有错误)。 例子(Linux,gcc-4.7):

$ cat > test.c #include <stdbool.h> #include <stdio.h> ^D $ gcc -H -fSyntax-only test.c . /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stdbool.h . /usr/include/stdio.h .. /usr/include/features.h ... /usr/include/x86_64-linux-gnu/bits/predefs.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/bits/wordsize.h .... /usr/include/x86_64-linux-gnu/gnu/stubs-64.h .. /usr/lib/gcc/x86_64-linux-gnu/4.7/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.7/include/stddef.h .... /usr/include/wchar.h ... /usr/lib/gcc/x86_64-linux-gnu/4.7/include/stdarg.h .. /usr/include/x86_64-linux-gnu/bits/stdio_lim.h .. /usr/include/x86_64-linux-gnu/bits/sys_errlist.h

每行开头的点数是#include嵌套深度。

如果你使用gcc,你可以用类似的东西检查一个特定的文件

echo '#include <stdbool.h>' | cpp -H -o /dev/null 2>&1 | head -n1

-H要求预处理器递归地打印所有包含的文件。 head -n1只是从那里输出的第一行,忽略任何文件包含的命名头(虽然stdbool.h特别可能不)。

以我的电脑为例,上面的输出

. /usr/lib/gcc/x86_64-linux-gnu/4.6/include/stdbool.h

locate stdio.h

要么

mlocate stdio.h

但如果您从未更新过,则需要依赖数据库

sudo updatedb

你也可以查询gcc知道gcc自己扫描的认目录是什么:

gcc -print-search-dirs

在预处理过程中,所有的预处理器指令将被替换为实际值。 像宏扩展,代码注释去除包括文件代码等… … –

我们可以使用'CPP' – C PreProcessor命令来检查它。

例如在命令行中,

cpp Filename.c

它将显示预处理的输出

一种方法,如果您知道包含文件名称,将使用find:

cd / find . -name "stdio.h" find . -name "std*.h"

这将需要一段时间,因为它通过每个目录。

使用gcc -v ,你可以检查包含路径。 通常,包含文件位于/usr/include或/usr/local/include具体取决于库安装。

大多数标准头文件存储在/usr/include 。 它看起来像stdbool.h存储在别的地方,并取决于你使用的编译器。 例如,g ++将其存储在/usr/include/c++/4.7.2/tr1/stdbool.h而clang将其存储在/usr/lib/clang/3.1/include/stdbool.h 。

我认为通用的路径是:

/ usr / lib / gcc / $(ls / usr / lib / gcc /)/ $(gcc -v 2>&1 | tail -1 | awk'{print $ 3}')/ include / stdbool.h

当我在寻找(在Fedora 25上)时,我使用了“whereis stdio.h”对于我来说,它在/usr/include/stdio.h,/usr/shar/man/man3/stdio,3.gx中。 但是,当你正在寻找文件,使用whereis或找到

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐