错误编译:Linux的/ module.h中:没有这样的文件或目录 [英] error compiling: linux/module.h: No such file or directory

查看:7830
本文介绍了错误编译:Linux的/ module.h中:没有这样的文件或目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个简单的模块:

 的#define __KERNEL__
#定义模块
#包括LT&;的Linux / kernel.h>
#包括LT&; Linux的/ - module.h中GT;INT的init_module(无效)
{
    printk的(你好,世界\\ n);
    返回0;
}虚空在cleanup_module(无效)
{
    printk的(再见\\ n);
}

和使用下面的命令编译它:

  CC -c hello.c中

但我发现了这个错误:

 的linux / module.h中:没有这样的文件或目录

有什么建议?

编辑:
我用这个commad:

  CC -I在/ usr / src / linux中报头-3.0.0-17-通用/包括-c hello.c中

和它向前走了一步,现在我得到这个错误:

 在文件从/usr/src/linux-headers-3.0.0-17-generic/include/linux/kernel.h:13:0包括,
                 从的hello.c:3:
/usr/src/linux-headers-3.0.0-17-generic/include/linux/linkage.h:5:25:致命错误:ASM / linkage.h:没有这样的文件或目录
编译终止。


解决方案

第一件事,你需要的 内核源代码 。许多混淆用户空间的头和内核空间的头,因为很多人有相同的文件夹结构。大部分的发行版的只有用户空间标题和不内核空间的。

一般制作是用来建立一个内核模块,而不是裸 CC 。按照简单的一步一步的解释给出的的Hello World 内核模块。 HTML>这里

I've written a simple module:

#define __KERNEL__
#define MODULE
#include <linux/kernel.h> 
#include <linux/module.h>

int init_module(void)
{
    printk("Hello, world\n");
    return 0;
}

void cleanup_module(void)
{
    printk("Goodbye\n");
}

and compiling it with this command:

cc -c hello.c

but I'm getting this error:

 linux/module.h: No such file or directory

any suggestions?

EDIT: I used this commad:

cc -I/usr/src/linux-headers-3.0.0-17-generic/include -c hello.c

and it goes one step ahead, now I get this error:

In file included from /usr/src/linux-headers-3.0.0-17-generic/include/linux/kernel.h:13:0,
                 from hello.c:3:
/usr/src/linux-headers-3.0.0-17-generic/include/linux/linkage.h:5:25: fatal error: asm/linkage.h: No such file or directory
compilation terminated.

解决方案

First thing you need the kernel sources. Many confuse user space headers and kernel space headers because many of them have the same folder structure. Most of the distros only have the user space headers and not the kernel space ones.

And generally make is used to build a kernel module and not a bare cc. Follow the simple step-by-step explained Hello World kernel module given here

这篇关于错误编译:Linux的/ module.h中:没有这样的文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆