内核模块构建失败:sys/types.h:没有这样的文件或目录

问题描述:

由于缺少.h文件,我无法构建内核模块。我在Ubuntu 14.04上构建模块。内核模块构建失败:sys/types.h:没有这样的文件或目录

这是make文件我用:

$ 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 

这是 '制作' 的输出:

$ 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. 

文件SYS/types.h中存在:

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

和测试方案,其中包括它编译:

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

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

我看了几个帖子,并确保我有libc6-dev和build-essential安装。

任何想法?

+0

我会认为你有正确的包,但有上市AMD64特定的一个。 http://packages.ubuntu.com/search?searchon=contents&keywords=sys%2Ftypes.h&mode=&suite=precise&arch=any – 2014-08-31 06:20:33

+0

你可以尝试寻找包含路径海合会期待中也是如此。回声| cpp -Wp,-v – 2014-08-31 06:24:37

当你正在开发一个Linux内核模块,你应该忘掉标准C库的舒适(Glibc的)。相反,你将不得不使用的内核C. 所以,你应该写

#include <linux/types.h> 

它会解决问题。