Can anyone please explain me why the header files are separted into include directory as well as under arch?

If I want to link my source code to include the header files, where should I actually take it from?




I am writing a program on a ARM host ( not cross compiling )

Can someone explain the structure of header files in the kernel? How are they spread and the logic behind it?

1 Answer 1


If you’re writing a userspace program, you shouldn’t use the kernel headers directly (whether from arch or include — the latter include the former as appropriate for your architecture). You need to use the headers prepared for use by userspace programs. These are typically available in distributions as a separate package, e.g. linux-libc-dev on Debian; or you can prepare them yourself by following the instructions linked above.

As to the organisation of the headers in the kernel, all the common headers are in include and its sub-directories, and the architecture-specific headers are in sub-directories of the appropriate arch directory. In most cases you’d include headers from include (when writing kernel code).

  • With common headers you mean, that the common headers are used independent of the architecture and as soon as there is a variation in the header, this header is deleted and ported to each and every architecture? I am saying delete, because, I could not find any symbolic links between the include and arch. So, how does the kernel find the includes related to the arch? Understood your answer regarding userspace, but my query about the structure of header files remains open. Mar 23, 2017 at 17:43
  • When variations occur, those variations would be isolated in arch-specific headers; it would be unusual for a header to be deleted entirely. There are no symlinks between include and arch; the appropriate arch-specific header paths are added to the compiler’s include path. (So you just use e.g. #include <asm/tce.h>, even though that’s arch-specific.) I’ll add this to my answer and try to expand it to address your question on the structure a bit more, but the latter is rather broad. Mar 23, 2017 at 19:44
  • Could it be possible that a include file of the same name is present under both /include as well as /arch? Coz it might raise a conflict. Sep 6, 2018 at 10:14
  • Include files of the same name are present under linux/include and arch, but they don’t create conflicts because all the arch headers are in paths which don’t appear under linux/include (asm or uapi, so you need to say #include <asm/compat.h> for example to include the arch-specific version). As mentioned in the answer, when writing kernel code, you normally only include files which are linux/include, and those files take care of including arch-specific versions as appropriate. Sep 6, 2018 at 11:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.