- 论坛徽章:
- 0
|
平台 redhat 8.0 内核 2.4.18-14
- /* hello.c */
- /* The necessary header files */
- /* Standard in kernel modules */
- #include <linux/kernel.h>; /* We're doing kernel work */
- #include <linux/module.h>; /* Specifically, a module */
- /* Deal with CONFIG_MODVERSIONS */
- #if CONFIG_MODVERSIONS==1
- #define MODVERSIONS
- #include <linux/modversions.h>;
- #endif
- /* Initialize the module */
- int init_module()
- {
- printk("Hello, world - this is the kernel speaking\n");
- /* If we return a non zero value, it means that
- * init_module failed and the kernel module
- * can't be loaded */
- return 0;
- }
- /* Cleanup - undid whatever init_module did */
- void cleanup_module()
- {
- printk("Short is the life of a kernel module\n");
- }
复制代码
- # Makefile for a basic kernel module
- CC=gcc
- MODCFLAGS := -Wall -DMODULE -D__KERNEL__ -DLINUX
- hello.o: hello.c /usr/include/linux/version.h
- $(CC) $(MODCFLAGS) -c hello.c
- echo insmod hello.o to turn it on
- echo rmmod hello to turn if off
- echo
- echo X and kernel programming do not mix.
- echo Do the insmod and rmmod from outside X
复制代码
问题一:
我在执行make后有这样一句警告:
hello.c: In function `init_module':
hello.c:27: warning: implicit declaration of function `printk'
意思应该是 对printk函数的声明模糊,请问如何解决这个警告问题?
问题二:
我试图用insmod命令将 hello.o插入内核中,但系统返回如下信息:
hello.o: kernel-module version mismatch
hello.o was compiled for kernel version 2.4.9-9
while this kernel is version 2.4.18-14.
意思应该是说 内核版本的冲突问题。
请问应如何解决该问题? |
|