Why is stddef.h not in /usr/include?

我的未来我决定 提交于 2019-12-04 03:17:06

问题


I have compiled the gnu standard library and installed it in $GLIBC_INST.

Now, I try to compile a very simple programm (using only one #include : #include <stdio.h>):

gcc --nostdinc -I$GLIBC_INST/include foo.c

The compilation (preprocessor?) tells me, that it doesn't find stddef.h.

And indeed, there is none in $GLIBC_INST/include (nor is there one in /usr/include). However, I found a stddef.h in /usr/lib/gcc/x86_64-unknown-linux-gnu/5.3.0/include.

Why is that file not under /usr/include? I thought it belonged to the standard c library and should be installed in $GLIBC_INST/include.

How can I compile my foo.c with the newly installed standard library when it doesn't seem to come with a stddef.h?

Edit: Clarification

I feel that the title of this question is not optimal. As has been pointed out by some answers, there is not a requirement for stddef.h to be in /usr/include (or $GLIBC_INST/include, for that matter). I do understand that.

But I am wondering how I can proceed when I want to use $GLIBC_INST. It seems obvious to me (although I might be wrong here) that I need to invoke gcc with --nostdinc in order to not use the system installed header files. This entails that I use -I$GLIB_INST/include. This is clear to me.

Yet, what remains unclear to me is: when I also add -I/usr/lib/gcc/x86..../include, how can I be sure that I do have in fact the newest header files for the freshly compiled glibc?


回答1:


That's because files under /usr/include are common headers that provided by the C library, for example, glibc, while the files at /usr/lib/gcc are specific for that particular compiler. It is common that each compiler has their own different implementation of stddef.h, but they will use the same stdio.h when links to the installed C library.




回答2:


When you say #include <stddef.h> it does not require that /usr/include/stddef.h exists as a file on disk at all. All that is required of an implementation is that #include <stddef.h> works, and that it gives you the features that header is meant to give you.

In your case, the implementation put some of its files in another search path. That's pretty typical.




回答3:


Why is that file not under /usr/include?

Because there's absolutely no requirement for standard headers to be located at /usr/include/.

The implementation could place them anywhere. The only guarantee is that when you do #include <stddef.h>, the compiler/preprocessor correctly locates and includes it. Since you disable that with -nostdinc option of gcc, you are on your own (to correctly give the location of that header).



来源:https://stackoverflow.com/questions/37158651/why-is-stddef-h-not-in-usr-include

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!