Page 1 of 2 12 LastLast
Results 1 to 10 of 12

Thread: Compiling kernel module problem with header

  1. #1
    Join Date
    Nov 2011
    Beans
    7

    Question Compiling kernel module problem with header

    I'm programming a pretty simple kernel module just to learn. I'm in a Ubuntu 11.04 box.

    The point is that my module includes these libraries at beginning of its source code:

    Code:
    #include <linux/kernel.h>
    #include <linux/module.h>
    #include <linux/init.h>
    #include <sys/types.h>
    To compile my source code I have a makefile like this:

    Code:
    obj-m += mymod.o
    
    all:
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
    
    clean:
    	make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

    Problem is that when I try compile my source code doing "make" I get this error:

    Code:
    fatal error: sys/types.h: no such file or directory
    compilation terminated.
    I've been searching the web for any solution but althought it seems I'm not the very first with this problem I've got no clear solution for this.

    Before compiling I had already installed build-essentials, libc6-dev, linux-headers-generic-pae and linux-source. Besides, I've checked I have sys/types.h at: /usr/include/sys/types.h, so I'm sure I have that header but somehow compiler doesn't find it.

    Thanks for your help.

    Dante

  2. #2
    Join Date
    Nov 2011
    Beans
    7

    Re: Compiling kernel module problem with header

    OK, I guess I've found the solution so I reply myself to leave it registered.

    Problem was (I suppose) I'm trying to compile a kernel module so I have no access to userland libraries. I'm not sure because I'm a noob in kernel modules programming, but I think sys/types.h is a userland library. So switching to a kernel space library alternative like linux/types.h should work. I tried that way, changing my include to linux/types.h, and it compiled properly

  3. #3
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,292
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Compiling kernel module problem with header

    There is no sys/types.h in Linux, it is a BSD thing I think (I have it on OS X).

  4. #4
    Join Date
    Nov 2011
    Beans
    7

    Re: Compiling kernel module problem with header

    It may come from BSD world, but now it's not exclusive from there.

    As far as I know, doing a "dpkg-query -S /usr/include/sys/types.h", that header is provided by libc6-dev package from Ubuntu repositories.

  5. #5
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,292
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Compiling kernel module problem with header

    Code:
    firas@itsuki ~ % dpkg-query -S /usr/include/sys/types.h
    dpkg-query: no path found matching pattern /usr/include/sys/types.h.

  6. #6
    Join Date
    Nov 2011
    Beans
    7

    Re: Compiling kernel module problem with header

    Try to install libc6-dev package and run command again...

  7. #7
    Join Date
    Nov 2011
    Beans
    7

    Re: Compiling kernel module problem with header

    Dpkg-query works over files already present in your system.

    If you have not installed a package its files are not registered in the database dpkg-query uses.

  8. #8
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,292
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Compiling kernel module problem with header

    *sigh*

    Code:
    firas@itsuki ~ % dpkg -l | grep libc6-dev
    ii  libc6-dev                                      2.13-20ubuntu5                          Embedded GNU C Library: Development Libraries and Header Files
    firas@itsuki ~ % dpkg-query -S /usr/include/sys/types.h
    dpkg-query: no path found matching pattern /usr/include/sys/types.h.
    I know how dpkg-query works, thank you very much.

  9. #9
    Join Date
    Nov 2011
    Beans
    7

    Re: Compiling kernel module problem with header

    It's strange ... maybe its a problem with libc6-dev package version. Mine has that header, look:


    Code:
    @Camelot:~$ dpkg-query -S /usr/include/sys/types.h
    libc6-dev: /usr/include/sys/types.h
    @Camelot:~$ dpkg -L libc6-dev | grep types.h
    /usr/include/bits/ioctl-types.h
    /usr/include/bits/pthreadtypes.h
    /usr/include/bits/types.h
    /usr/include/bits/xtitypes.h
    /usr/include/bits/ipctypes.h
    /usr/include/sys/bitypes.h
    /usr/include/sys/types.h
    /usr/include/nl_types.h
    /usr/include/rpc/types.h
    /usr/include/inttypes.h
    @Camelot:~$ dpkg -l | grep libc6-dev
    ii  libc6-dev                            2.13-0ubuntu13                             Embedded GNU C Library: Development Libraries and Header Files
    @Camelot:~$ uname -a
    Linux Camelot 2.6.38-13-generic-pae #52-Ubuntu SMP Tue Nov 8 17:50:45 UTC 2011 i686 athlon i386 GNU/Linux
    @Camelot:~$ cat /etc/issue
    Ubuntu 11.04 \n \l
    I don't know why you have not that header but mine comes from that package as you can see.

  10. #10
    Join Date
    Nov 2005
    Location
    Bordeaux, France
    Beans
    11,292
    Distro
    Ubuntu 12.04 Precise Pangolin

    Re: Compiling kernel module problem with header

    If you are not using the latest version of Ubuntu, say so. Unless otherwise stated, I always assume the latest version.

Page 1 of 2 12 LastLast

Tags for this Thread

Bookmarks

Posting Permissions

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