简体   繁体   中英

kernel module build fails: sys/types.h: No such file or directory

I'm unable to build a kernel module due to a missing .h file. I'm building the module on Ubuntu 14.04.

This is the make file I use:

$ cat Makefile 
obj-m += my_module.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

And this is the output of 'make':

$ make
make -C /lib/modules/3.13.0-34-generic/build M=/home/user/location modules
make[1]: Entering directory `/usr/src/linux-headers-3.13.0-34-generic'
  CC [M]  /home/user/location/my_module.o
/home/user/location/my_module.c:2:23: fatal error: sys/types.h: No such file or directory
 #include <sys/types.h>
                       ^
compilation terminated.

The file sys/types.h exists:

/usr/include/x86_64-linux-gnu/sys/types.h

And a test program which includes it compiles:

$ cat test.c 
#include <sys/types.h>
#include <stdio.h>

int main()
{
    printf ("test\n");
    return 0;
}
$ gcc -o test test.c 
$ 

I looked at several posts and made sure I have libc6-dev and build-essential installed.

Any ideas?

When you are developing a Linux kernel module, you should forget about the comforts of Standard C library(Glibc).Instead , you will have to use the Kernel C. So , you should write

#include <linux/types.h>

It will solve the problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM