Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 335
René Nyffenegger Avatar asked May 11 '16 09:05

René Nyffenegger


People also ask

Where is Stddef h in Linux?

The stddef. h header file is located in /usr/lib/gcc/x86_64-redhat-linux/3.4. 2/include so if the “GCCINC” directory is not set correctly, it wont be able to find the file.

What does Stddef h mean in C?

h is a header file in the standard library of the C programming language that defines the macros NULL and offsetof as well as the types ptrdiff_t, wchar_t, and size_t.


1 Answers

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.

like image 164
fluter Avatar answered Oct 12 '22 23:10

fluter