1.编译错误(其实这个问题和 Makefile有很大关系)
53vi.Com
53vi.Com
2.Invalid module format 错误
53vi.Com
3.insmod: error inserting './hello.ko': -1 File exists
资讯先锋网
开发环境 53vi.Com - [资讯前沿 技术先锋]
内核版本:2.6.22(我下载的最新版本)
gcc:gcc (GCC) 4.1.2 53vi.Com - [资讯前沿 技术先锋]
53vi.Com
Makefile 资讯先锋网
gcc -D__KERNEL__ -DMODULE -DLINUX -I /usr/local/src/linux2.4/include -c -o hello.o hello.c
资讯先锋网
上面这种写法适合 2.4 版本的内核,在2.6下用这种写法很可能导致许多编译错误,即使编译通过也会产生 Invalid module format 错误。
资讯先锋网
资讯先锋网
2.6下正确的 Makefie 如下:
53vi.Com
资讯先锋网
53vi.Com
|
使用上面的 Makefie 同时也解决了 Invalid module format 错误
资讯先锋网
insmod: error inserting './hello.ko': -1 File exists 错误解决 53vi.Com
第一次insmod ./hello.ko 没有输出表示你的模块被正常载入了,后来的错误是你重复载入这个模块导致的
资讯先锋网
用命令 lsmod | grep hello 看看是不是有这个模块?
53vi.Com - [资讯前沿 技术先锋]
用命令 tail /var/log/messages 资讯先锋网
有 hello,world 53vi.Com
53vi.Com - [资讯前沿 技术先锋]
module程序正常执行。
资讯先锋网

现在位置: