第一次编译模块总结
来源:互联网 发布:剑雨江湖602进阶数据 编辑:程序博客网 时间:2024/06/05 00:40
1:模块代码:.c
#include <linux/init.h>
#include <linux/module.h>
#include <linux/moduleparam.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT,"load hello module");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT,"unload hello module");
}
module_init(hello_init);
module_exit(hello_exit);
MODULE_ALIAS("mhwgo-hello");
2:makefile文件:(只有一句)
obj-m :=helloworld.o
3:执行:
sudo make -C /usr/src/linux-headers-2.6.28-16/ M=$(pwd) modules
[root@liu-desktop linux26]#insmod hellomod.ko
[root@liu-desktop linux26]#lsmod |grep hellomod
lsmod |grep hellomod
[root@liu-desktop linux26]#rmmod hellomod
注意:如果出现下面错误,那应该是内核版本号对不上,version magic不对
insmod: error inserting 'hellomod.ko': -1 Invalid module format
此时,你用sudo tail /var/log/messages
你在最后一行应该看到类似下面的提示:
Dec 19 13:42:29 localhost kernel: hellomod: version magic '2.6.24.2 SMP mod_unload 686 4KSTACKS ' should be '2.6.27.7-134.fc10.i686 SMP mod_unload 686 4KSTACKS '
1:
进行模块编译前,最好下载一个完整的内核源码(不一定需要最新的),并对其进行编译。
编译所需的.config文件可以从系统中直接拷(如命令:cp /boot/config-2.6.28-16 .config)
2:
可能会用到的命令如下:
sudo apt-get install build-essential
sudo apt-get install libncurses*
ERROR: Kernel configuration is invalid.
include/linux/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.
make oldconfig && make prepare 这两条命令的作用?
执行:sudo make prepare
出现错误:
scripts/kconfig/conf -s arch/x86/Kconfig
CHK include/linux/version.h
UPD include/linux/version.h
CHK include/linux/utsrelease.h
UPD include/linux/utsrelease.h
SYMLINK include/asm -> include/asm-x86
make[1]: *** No rule to make target `kernel/bounds.c', needed by `kernel/bounds.s'. Stop.
make: *** [prepare0] Error 2
什么原因?
可能原因:由于缺少文件
解决办法:重新下载一个内核源程序,先把内核编译一遍,再来对模块进行编译。
问题3:
sudo apt-get install build-essential
or
sudo apt-get install build-essential linux-headers-$(uname -r)
正在读取软件包列表... 完成
正在分析软件包的依赖关系树
正在读取状态信息... 完成
现在没有可用的软件包 build-essential,但是它被其它的软件包引用了。
这可能意味着这个缺失的软件包可能已被废弃,
或者只能在其他发布源中找到
E: 软件包 build-essential 还没有可供安装的候选者
为什么失败?
解决:软件源列表不齐全,可以更新软件源。
问题4:
sudo apt-get install linux-source
sudo apt-get install glibc-source
作用?
问题5:
*** Unable to find the ncurses libraries or the
*** required header files.
*** 'make menuconfig' requires the ncurses libraries.
***
*** Install ncurses (ncurses-devel) and try again.
***
make[1]: *** [scripts/kconfig/dochecklxdialog] Error 1
make: *** [menuconfig] Error 2
这是什么问题?
原因:解决:软件源列表不齐全,可以更新软件源。
- 第一次编译模块总结
- 驱动模块编译总结
- 驱动模块编译总结
- opencv3.1.0+contrib模块编译总结
- 第一次总结
- 第一次总结
- 第一次总结
- 第一次总结
- 模块编译
- Android编译c++独立动态库模块时报错总结
- 第一次编译linux内核
- 第一次编译内核
- 第一次编译Linux内核
- 编译原理第一次作业
- FFmpeg第一次编译
- 编译原理第一次作业
- 第一次真正接触SAP模块
- 内核编译 & 模块编译
- c# DLL Import
- 双色球的技术性分析1
- DotNet关键知识点——WPF篇(三)
- 3G,戏说和细说
- listview和treeview,失去焦点,仍然选中。
- 第一次编译模块总结
- 精神病人的世界--第一篇《角色问题》
- jdk1.6.0 + mssql + tomcat如何配置环境变量
- Openoffice在redflag6下指定路径安装无法启动的问题
- 忘却
- 痛苦,但因祸得福,用Live Writer了
- AAC ADTS LATM 格式分析
- Cisco路由器配置基于L2TP的IPSec接入服务器
- 痛苦,但因祸得福,用上Live Writer了