- 论坛徽章:
- 0
|
*/
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");
static int hello_init(void)
{
printk(KERN_ALERT "Hello, world\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
}
module_init(hello_init);
module_exit(hello_exit);
以上为源程序,编译输入 gcc -o hell hello.c
出错hello.c: In function `hello_init':
hello.c:11: error: `KERN_ALERT' undeclared (first use in this function)
hello.c:11: error: (Each undeclared identifier is reported only once
hello.c:11: error: for each function it appears in.)
hello.c:11: error: syntax error before string constant
hello.c: In function `hello_exit':
hello.c:17: error: `KERN_ALERT' undeclared (first use in this function)
hello.c:17: error: syntax error before string constant
用Makefile可以通过,文件如下
ifeq ($(KERNELRELEASE),)
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
modules:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
modules_install:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
clean:
rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions
.PHONY: modules modules_install clean
else
obj-m := hello.o
endif
不用Makefile,怎么用命令去编译?以上的Makefile,谁能帮解释下(是不是自动生成了依赖性,obj-m := hello.o),等待高手解答?? |
|