关于最简单的驱动编译hello的问题,好纠结啊,有懂得大侠吗
嵌入式吧
全部回复
仅看楼主
level 4
Austin丁 楼主
这是原码
#include
#if defined(CONFIG_SMP)
#define _SMP_#
endif
#if defined(CONFIG_MODVERSIONS)#define MODVERSIONS#include #endif
#include
static _init int init_module(void){ printk(KERN_DEBUG "HELLO,KERNEL!\"); return 0;}
static _exit void cleanup_module(void){ printk(KERN_DEBUG "GOOD-BYE,kernel!\n");}
这是编译语句
gcc -D_KERNEL_ -I/usr/src/linux/include -DMODULE -Wall -O2 -c hello_kernel.c -o hello_kernel.o
出错的提示
hello_kernel.c:1:25: fatal error: linux/module.h: No such file or directorycompilation terminated.
2013年05月20日 14点05分 1
level 3
你这个是驱动那本书第一个hello模块例程吧,你把printk输出的第一个参数,优先级那个去掉试试
2013年05月21日 15点05分 2
对,是驱动那本书的第一个例程。最近在学驱动,我把优先级去掉了,可还是那个问题啊
2013年05月23日 13点05分
level 7
当然是根据提示的问题找啦,你对应目录下真的有这个module.h的文件吗?
2013年05月22日 02点05分 3
我是按照书上的例子写的,对驱动什么的刚学习,怎么查看对应的目录,如果目录里没有module.h的文件该怎么办呢,谢谢了
2013年05月23日 13点05分
level 5
我们学的驱动不是这么写的~~
2013年05月23日 16点05分 5
level 9
不要迷信书本,linux kernel日新月异,linux驱动开发那本书里面的很多例子在新版本上都已经无法编译了
对于如何编译内核,可以参考内核文档
http://kernel.org/doc/Documentation/kbuild/modules.txt
要编译你这个例子,
新建makefile
里面只有一句话
obj-m: = hello.o
shell上执行命令
$ make -C /lib/modules/`uname -r`/build M=$PWD (这是针对你正在运行的linux 内核,要不你就要指定linux source tree了)
good luck
欢迎交流!!
2013年05月24日 00点05分 6
感谢啊[真棒]
2013年05月24日 14点05分
level 8
编译时,-l /usr/src/2.6.30.10/
2013年05月24日 03点05分 7
虽然没成功,但还是谢谢了
2013年05月24日 14点05分
1