|
《LINUX系统分析与高级编程技术》书中讲到linux高级编程部分。
用一个简单的程序Hello Wo r l d介绍L i n u x内核模块的编程。
hello.c中的代码
- /* 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 */
- /* 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 */
复制代码
Makefile的内容
- # Makefile for a basic kernel module
- C C = g c c
- MODCFLAGS := -O6 -Wall -DCONFIG_KERNELD -DMODULE -D__KERNEL__ -DLinux
- h e l l o . 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
- e c h o
- echo X and kernel programming do not mix.
- echo Do the insmod and rmmod from outside X
复制代码
然后,我在redhat下,尝试了一下make
报错:
5:*** missing separate
照它的报错上讲应该是Makefile的第5行出错,即$(CC) $(MODCFLAGS) -c hello.c
我又多次尝试修改Makefile文件,还是同样的问题。
我甚至重启系统,进入text模式下,还是不行。
请各位高手帮忙看下是哪里出了错误。 |
|