Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    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.

  2. #2
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    12,852
    This is in your kernel source, right? If so, it should be like this (assuming 'include' refers to the default include directory):
    Code:
    #include <net/af_unix.h>
    If you need the ABSOLUTE path, then do this:
    Code:
    #include "/absolute-path-to-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.
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

  3. #3
    Quote Originally Posted by Rubberman View Post
    This is in your kernel source, right? If so, it should be like this (assuming 'include' refers to the default include directory):
    Code:
    #include <net/af_unix.h>
    If you need the ABSOLUTE path, then do this:
    Code:
    #include "/absolute-path-to-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.
    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)

  4. $spacer_open
    $spacer_close
  5. #4
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    12,852
    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!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •