内核驱动编写错误集(待续)

[root@localhost globalmem]# insmod globalmem.ko

insmod: error inserting 'globalmem.ko': -1 Invalid module format


内核加载出现错误: 错误主要有Makefile里面的内核版本跟PC系统的版本不一样,另外一个就是gcc版本问题;

第一个:

Makefile内容如下

obj-m :=globalmem.o
KERNEL_DIR :=/lib/modules/$(shell uname -r)/build
PWD :=$(shell pwd)
all:
        make -C $(KERNEL_DIR) SUBDIRS=$(PWD) modules
clean:
        rm *.o *.ko *.mod.c

这样的Makefile一般不会出现内核版本不对,有些人是固定的:比如

KERNEL_DIR :=/usr/src/linux-2.4.20-8   如果与当前的版本号(uname -r)不一致就会出错。


第二个:

查看gcc版本,我安装过4.1.2版本的gcc,所以默认是4.1.2,在/usr/local/bin/目录下:

[root@localhost globalmem]# gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: /usr/local/src/gcc-4.1.2/configure --enable-threads=posix --disable-checking --enable--long-long --host=i386-redhat-linux --with-system-zlib --enable-languages=c,c++,java
Thread model: posix
gcc version 4.1.2

[root@localhost globalmem]# which gcc
/usr/local/bin/gcc

查看/usr/bin下的gcc版本,也就是系统装的时候带的版本。

[root@localhost globalmem]# /usr/bin/gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)


由于自己不知道怎么改gcc版本,怎么改为3.2.2的,就做了一个软链接,

[root@localhost globalmem]# cd /usr/local/bin/

[root@localhost bin]# mv gcc gcc.old

[root@localhost bin]# ln -sf /usr/bin/gcc  /usr/local/bin/gcc

这样弄完后查看gcc版本:

[root@localhost bin]# gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info --enable-shared --enable-threads=posix --disable-checking --with-system-zlib --enable-__cxa_atexit --host=i386-redhat-linux
Thread model: posix
gcc version 3.2.2 20030222 (Red Hat Linux 3.2.2-5)



在make, [root@localhost globalmem]# insmod globalmem.ko 就可以成功了。


redhat9 下怎么改gcc版本    继续google中。。。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值