模块编译:未找到 asm/linkage.h 文件 [英] module compiling : asm/linkage.h file not found

查看:65
本文介绍了模块编译:未找到 asm/linkage.h 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编译hello world"内核模块的示例,在 ubuntu 11.04、内核 3.2.6、gcc 4.5.2 和 fedora 16、内核 3.2.7、gcc 4.6.7 上发现的问题.

I am trying to compile an example of "hello world" Kernel Module, problems found on ubuntu 11.04, kernel 3.2.6, gcc 4.5.2 and fedora 16, kernel 3.2.7, gcc 4.6.7.

代码:

#include <linux/module.h>
#include <linux/init.h>
MODULE_LICENSE("GPL");

static int __init hello_init (void)
{
printk("Hello module init
");
return 0;
}
static void __exit hello_exit (void)
{
printk("Hello module exit
");
}
module_init(hello_init);
module_exit(hello_exit);

编译:

gcc -D__KERNEL__ -I /usr/src/linux/include/ -DMODULE -Wall -O2 -c hello.c -o hello.o

错误:

在/usr/src/linux/include/linux/kernel.h:13:0 包含的文件中,来自/usr/src/linux/include/linux/cache.h:4,来自/usr/src/linux/include/linux/time.h:7,来自/usr/src/linux/include/linux/stat.h:60,来自/usr/src/linux/include/linux/module.h:10,来自 hello.c:1:/usr/src/linux/include/linux/linkage.h:5:25: 致命错误:asm/linkage.h:找不到文件

In file included from /usr/src/linux/include/linux/kernel.h:13:0, from /usr/src/linux/include/linux/cache.h:4, from /usr/src/linux/include/linux/time.h:7, from /usr/src/linux/include/linux/stat.h:60, from /usr/src/linux/include/linux/module.h:10, from hello.c:1: /usr/src/linux/include/linux/linkage.h:5:25: fatal error: asm/linkage.h: file not found

然后我发现在/usr/src/linux/include/中没有名为asm"的文件夹,而是asm-generic";所以我做了一个asm"到asm-generic"的软链接,然后重新编译:

then I found in /usr/src/linux/include/ there is no folder named 'asm' but 'asm-generic'; so I made a soft link 'asm' to 'asm-generic', and compiled agail:

这次的错误是:

在/usr/src/linux/include/linux/preempt.h:9:0 包含的文件中,来自/usr/src/linux/include/linux/spinlock.h:50,来自/usr/src/linux/include/linux/seqlock.h:29,来自/usr/src/linux/include/linux/time.h:8,来自/usr/src/linux/include/linux/stat.h:60,来自/usr/src/linux/include/linux/module.h:10,来自 hello.c:1:/usr/src/linux/include/linux/thread_info.h:53:29: 致命错误:asm/thread_info.h:找不到文件

In file included from /usr/src/linux/include/linux/preempt.h:9:0, from /usr/src/linux/include/linux/spinlock.h:50, from /usr/src/linux/include/linux/seqlock.h:29, from /usr/src/linux/include/linux/time.h:8, from /usr/src/linux/include/linux/stat.h:60, from /usr/src/linux/include/linux/module.h:10, from hello.c:1: /usr/src/linux/include/linux/thread_info.h:53:29: fatal error: asm/thread_info.h: file not found

所以我意识到我错了,但为什么呢?T_T

So I realized I was wrong, but why ? T_T

推荐答案

obj-m += hello.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

是构建模块的正确方法,请参阅kbuild 文档

is a proper way to build modules see kbuild documentation

要查看编译器调用之间的差异,您可以

And to see difference beetween your compiler invocation you could

cat /lib/modules/$(shell uname -r)/build/Makefile

并分析输出

这篇关于模块编译:未找到 asm/linkage.h 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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