我下載kernel-source-2.6.8 後解壓縮
把檔名改成 資料夾linux
obj-m := dev_ex.o
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean
改成
obj-m := dev_ex.o
all:
make -C /usr/src/linux
clean:
make -C /usr/src/linux
-----------------------------------------------------------
又出現下面錯誤
- 代碼: 選擇全部
make -C /usr/src/linux
make[1]: Entering directory `/usr/src/linux'
Makefile:415: .config: 沒有此一檔案或目錄
CHK include/linux/version.h
UPD include/linux/version.h
SYMLINK include/asm -> include/asm-i386
HOSTCC scripts/basic/fixdep
HOSTCC scripts/basic/split-include
HOSTCC scripts/basic/docproc
SHIPPED scripts/kconfig/zconf.tab.h
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/mconf.o
scripts/kconfig/mconf.c:91: error: static declaration of 'current_menu' follows non-static declaration
scripts/kconfig/lkc.h:63: error: previous declaration of 'current_menu' was here
make[3]: *** [scripts/kconfig/mconf.o] Error 1
make[2]: *** [silentoldconfig] Error 2
make[1]: *** [include/linux/autoconf.h] Error 2
make[1]: Leaving directory `/usr/src/linux'
make: *** [all] Error 2
下面是書上說法
你可以用 insmod 和 rmmod 工具來測試這個模區塊. 注意只有超級用戶(root)可以加載和卸載模區塊.
% make
make[1]: Entering directory `/usr/src/linux-2.6.10'
CC [M] /home/ldd3/src/misc-modules/hello.o
Building modules, stage 2.
MODPOST
CC /home/ldd3/src/misc-modules/hello.mod.o
LD [M] /home/ldd3/src/misc-modules/hello.ko
make[1]: Leaving directory `/usr/src/linux-2.6.10'
% su
root# insmod ./hello.ko
Hello, world
root# rmmod hello
Goodbye cruel world
root#