I generally approach this question like this. I'm on a Fedora 19 system but this will work on any distro that provides locate
services.
$ locate "linux/init.h" | grep include
/usr/src/kernels/3.13.6-100.fc19.x86_64.debug/include/linux/init.h
/usr/src/kernels/3.13.7-100.fc19.x86_64.debug/include/linux/init.h
/usr/src/kernels/3.13.9-100.fc19.x86_64/include/linux/init.h
/usr/src/kernels/3.13.9-100.fc19.x86_64.debug/include/linux/init.h
Your paths will be different but the key take away is that you want to ask locate
to find what's being included ("linux/init.h") and filter these results looking for the keyword include
.
There are also distro specific ways to search for these locations using RPM (Redhat) or APT (Debian/Ubuntu).
gcc
Notice however that the paths within the C/C++ file are relative:
#include <linux/init.h>
This is so that when you call the compiler, gcc
, you can override the location of the include files that you'd like to use. This is controlled through the switch -I <dir>
.
excerpt from man gcc
-I dir
Add the directory dir to the list of directories to be searched for
header files. Directories named by -I are searched before the
standard system include directories. If the directory dir is a
standard system include directory, the option is ignored to ensure
that the default search order for system directories and the special
treatment of system headers are not defeated . If dir
begins with "=", then the "=" will be replaced by the sysroot
prefix; see --sysroot and -isysroot.
External modules
There's this article which discusses how one would incorporate the development of their own kernel modules into the "build environment" that's included with the Linux kernel. The article is titled: Driver porting: compiling external modules. The organization of the Kernel's makefile is also covered in this article: makefiles.txt.
For Kernel newbies there's also this article: KernelHeaders from the kernelnewbies.org website.
NOTE: The Kernel uses the KBuild system which is covered here as part of the documentation included with the Kernel.
References