首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 操作系统 > UNIXLINUX >

linux kernel 测试资料编译失败

2012-07-15 
linux kernel 测试文件编译失败学习《Linux设备驱动程序第三版.pdf》,第2章的给的测试程序,无法再虚拟机上编

linux kernel 测试文件编译失败
学习《Linux设备驱动程序第三版.pdf》,第2章的给的测试程序,无法再虚拟机上编译成功。主要原因是makefile不正确,请帮忙修改一下。
错误提示信息:
make[1]: Entering directory `/usr/src/kernels/2.6.29.4-167.fc11.i686.PAE'
make[2]: *** No rule to make target `/mnt/hgfs/share/kernel_code/kernel_hello.c', needed by `/mnt/hgfs/share/kernel_code/kernel_hello.o'. Stop.
make[1]: *** [_module_/mnt/hgfs/share/kernel_code] Error 2
make[1]: Leaving directory `/usr/src/kernels/2.6.29.4-167.fc11.i686.PAE'
make: *** [default] Error 2

书中的makefile脚本(没有指定编译器,我不清楚应该指定那个编译器)

Python code
# If KERNELRELEASE is defined, we've been invoked from the# kernel build system and can use its language.ifneq ($(KERNELRELEASE),)obj-m := kernel_hello.o# Otherwise we were called directly from the command# line; invoke the kernel build system.elseKERNELDIR ?= /lib/modules/$(shell uname -r)/build#ehco $(KERNELDIR)PWD := $(shell pwd)#echo $(PWD)default:    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

源代码:
C/C++ code
#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);


请问应该如何修改makefile

[解决办法]
对于第一个问题:当你使用伪终端执行的时候是看不到打印的字符的,如果你切换到真正的字符界面(终端)在insmod,就能够看到打印的消息了;
第二个问题没有接触过
探讨
问题已经解决。原因是源码文件用了.cpp的后缀导致编译失败。
但是又遇到新的问题:
1.inmod kernel_hello.ko 和rmmod kernel_hello.ko 并没有打印任何字符串
2.如果源码文件用cpp后缀如何编译呢?

热点排行