hello world 模块编译
来源:互联网 发布:ubuntu 12.04 samba 编辑:程序博客网 时间:2024/05/21 22:51
1、test.c
#include <linux/init.h>#include <linux/module.h>static int hello_init(void){printk(KERN_INFO "Hello World enter \n");}static int hello_exit(void){printk(KERN_INFO "Hello World exit\n");}module_init(hello_init);module_exit(hello_exit);
2、Makefile
obj-m :=test.o
3、在shell 中键入
make -C /usr/src/linux-3.3.1/linux-3.3.1/ M=~/Documents/test/ modules
4、在执行时,出现下面错误:
insmod: error inserting './test.ko': -1 Invalid module format
出错信息出现在 /var/log/message 中。
Apr 7 16:27:33 ubuntu kernel: [ 7026.609031] test: disagrees about version of symbol module_layout
而模块的相关信息可以通过 modinfo 来看。
wangkai@ubuntu:~/Documents/test$ sudo modinfo test.kofilename: test.kolicense: Dual BSD/GPLsrcversion: A683B0513DFC18A40C79C30depends: vermagic: 3.3.1-20120406 SMP mod_unload modversions 68
内核无法加载模块的原因是因为记载版本号的字符串和当前正在运行的内核模块的不一样,这个版本印戳作为一个静态的字符串存在于内核模块中,叫vermagic
真正的原因是由于当前的内核源码和系统版本不相匹配。 当前正在运行的系统的 为ubuntu 10.10的内核。而源码则为 3.3.1的源码。故出错。
5、解决问题的方法 是
$ make -C /usr/src/linux-headers-2.6.35-22-generic/ M=~/Documents/test/ modules
二、通过写Makefile的方法,使得模块的勾走更加简单。
1、最简单的方法是,把上面的命令写进Makefile中即可。
obj-m :=test.okernel_modules: make -C /usr/src/linux-headers-2.6.35-22-generic/ M=/home/wangkai/Documents/test/ modulesclean: make -C /usr/src/linux-headers-2.6.35-22-generic/ M=/home/wangkai/Documents/test/ clean
2、但是这种方式,不够通用,可以写得更加通用些。
KVER = $(shell uname -r)obj-m :=test.okernel_modules: make -C /lib/modules/$(KVER)/build M=$(PWD) modulesclean: make -C /lib/modules/$(KVER)/build M=$(PWD) clean
编译时,只需
make
重新编译时,只需
make clean
- hello world 模块编译
- hello world 模块编译
- Android编译环境--- 编译hello world模块
- 编译Native C的hello,world模块
- Hello World模块的编译和运行
- 编译内核模块Hello World V1.0
- 编译内核模块Hello World V2.0
- 编译内核模块Hello World V3.0
- 编译内核模块Hello World V4.0
- linux内核模块编译,最简单的hello world
- ubuntu12.04 编译第一个hello world模块!
- hello world 模块
- LDD3 hello world 模块
- hello world 内核模块
- Drupal Hello World模块
- (二) Hello World模块
- hello world!(驱动模块)
- hello world---编译链接
- VB 6.0中Byte数组和String转换
- Nucleus系统源码分析与学习
- APUE函数笔记十五: 高级进程间通信(部分)
- 深入理解操作系统 csapp.h的使用
- 计算机启动过程
- hello world 模块编译
- 分享Silverlight/WPF/Windows Phone/HTML5一周学习导读(3月26日-3月31日)
- PHP的foreach
- This application is currently offline
- Windows Mobile 5.0 SDK 下载地址收藏
- Linux下getsockopt/setsockopt 函数说明
- 判断字符串是否包含在另外一个字符串中。
- IPhone屏幕录制工具Display Recorder使用教程
- vc++6.0 + Access