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

江枫思渺然 提交于 2019-12-11 12:48:03

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/25589407/kernel-module-build-fails-sys-types-h-no-such-file-or-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!