Results 1 to 4 of 4
hello,
i want to include Af_unix.h(include/net/af_unix.h) file in my sche,h file of linux. but when I compile the kernel it gives me error Undefined reference to af_unix.h. Similar is the ...
- 02-01-2012 #1Just Joined!
- Join Date
- Dec 2011
- Posts
- 29
Including file in a makefile
hello,
i want to include Af_unix.h(include/net/af_unix.h) file in my sche,h file of linux. but when I compile the kernel it gives me error Undefined reference to af_unix.h. Similar is the case when i include sys/types.h and unistd.h
I have also included the proper directory i mean for unistd.h i write
#include<linux/unistd.h>
Also i have properly included all the other files.
Can anyone please help me out why I am getting this error for all the files I am trying to include.
may be I need to make changes in the Makefile of the kernel
Please tell me out what are the required changes to be made.

- 02-02-2012 #2Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,961
This is in your kernel source, right? If so, it should be like this (assuming 'include' refers to the default include directory):
If you need the ABSOLUTE path, then do this:Code:#include <net/af_unix.h>
Note the difference between angle brackets in the first example, and double-quotes in the second. While not always important, in some cases this can be critical, though I won't explain the differences at this point.Code:#include "/absolute-path-to-include/net/af_unix.h"
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!
- 02-05-2012 #3Just Joined!
- Join Date
- Dec 2011
- Posts
- 29
As you said i have included the socket.h file using its absolute path
But socket.h include a file named features.h
so when I compile my kernel module it gives me error : /usr/include/sys/socket.h: No such file or directory
same error is given for all the files which are included in socket.h
I think we should make changes in the makefile of the kernel module
(I am writing my own kernel module)
- 02-05-2012 #4Linux Guru
- Join Date
- Apr 2009
- Location
- I can be found either 40 miles west of Chicago, or in a galaxy far, far away.
- Posts
- 8,961
Ok. You need to add to the beginning of your CFLAGS make variable the flag "-I path-to-kernel-include-dir" where path-to-kernel-include-dir is usually something like "../../include" (assuming that the kernel include directory is 2 levels above your module build directory), otherwise it will likely be set to the default /usr/include path, which is where it would look to resolve those files. The error you quote about "/usr/include/sys/socket.h: No such file or directory" is the proof of that.
Sometimes, real fast is almost as good as real time.
Just remember, Semper Gumbi - always be flexible!


Reply With Quote

