LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 627|回复: 1

一个关于linux内核模块编程的基础问题

[复制链接]
发表于 2005-3-27 01:18:55 | 显示全部楼层 |阅读模式
《LINUX系统分析与高级编程技术》书中讲到linux高级编程部分。
用一个简单的程序Hello Wo r l d介绍L i n u x内核模块的编程。
hello.c中的代码

  1. /* hello.c */
  2. /* The necessary header files */
  3. /* Standard in kernel modules */
  4. #include <linux/kernel.h> /* We're doing kernel work */
  5. #include <linux/module.h> /* Specifically, a module */
  6. /* Initialize the module */
  7. int init_module()
  8. {
  9. printk("Hello, world - this is the kernel speaking\n");
  10. /* If we return a non zero value, it means that init_module failed and
  11. * the kernel module can't be loaded */
  12. return 0;
  13. }
  14. /* Cleanup - undid whatever init_module did */
复制代码

Makefile的内容

  1. # Makefile for a basic kernel module
  2. C C = g c c
  3. MODCFLAGS := -O6 -Wall -DCONFIG_KERNELD -DMODULE -D__KERNEL__ -DLinux
  4. h e l l o . o : hello.c /usr/include/linux/version.h
  5. $(CC)  $(MODCFLAGS)  -c  hello.c
  6. echo insmod hello.o to turn it on
  7. echo rmmod hello to turn if off
  8. e c h o
  9. echo X and kernel programming do not mix.
  10. echo Do the insmod and rmmod from outside X
复制代码

然后,我在redhat下,尝试了一下make
报错:
5:*** missing separate

照它的报错上讲应该是Makefile的第5行出错,即$(CC)  $(MODCFLAGS)  -c  hello.c
我又多次尝试修改Makefile文件,还是同样的问题。
我甚至重启系统,进入text模式下,还是不行。
请各位高手帮忙看下是哪里出了错误。
发表于 2005-3-27 10:33:18 | 显示全部楼层
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表