作者suspect1 (嫌犯)
看板LinuxDev
标题[问题] 编译hello world 模组的问题
时间Wed May 30 11:02:30 2007
Dear All:
请教有关编译一个简单的模组的问题,以下是我的程式码:
********************************************************
hello.c:
#include <linux/module.h>
#if defined(CONFIG_SMP)
#define __SMP__
#endif
#if defined(CONFIG_MODVERSIONS)
#define MODVERSIONS
#include <linux/modversions.h>
#endif
#include <linux/kernel.h>
int init_module(void)
{
printk(KERN_DEBUG "Hello, kernel!\n");
return 0;
}
void cleanup_module(void)
{
printk(KERN_DEBUG "Good-bye, kernel!\n");
}
**************************************************************
Makefile:
# standards
INCLUDE = /usr/src/kernels/2.6.18-1.2798.fc6-i686/hello
CC = gcc
CFLAGS = -D__KERNEL__ -I$(INCLUDE) -DMODULE -Wall -O2
TARGET = hello
SRC = hello.c
all: $(TARGET).o
clean:
rm -f *.o *~ core
********************************************************************
错误讯息:
gcc -D__KERNEL__ -I/usr/src/kernels/2.6.18-1.2798.fc6-i686/hello -DMODULE
-Wall -O2 -c -o hello.o hello.c
hello.c:4:26: 错误:linux/module.h:没有此一档案或目录
hello.c: 在函式 「init_module」 中:
hello.c:19: 警告:隐含宣告函式 「printk」
hello.c:19: 错误:「KERN_DEBUG」 未宣告 (在此函式内第一次使用)
hello.c:19: 错误:(即使在一个函式内多次出现,每个未宣告的识别码在其
hello.c:19: 错误:所在的函式内只报告一次。)
hello.c:19: 错误:expected 「)」 before string constant
hello.c: 在函式 「cleanup_module」 中:
hello.c:25: 错误:「KERN_DEBUG」 未宣告 (在此函式内第一次使用)
hello.c:25: 错误:expected 「)」 before string constant
make: *** [hello.o] Error 1
**************************************************************************
看上面的错误讯息,好像是没找到module.h,我的module.h所在的路径为
/usr/src/kernels/2.6.18-1.2798.fc6-i686/include/linux/module.h
但我修改了程式好几次,仍然出现找不到的错误讯息,请问我该如改呢?
谢谢!
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.112.115.2
1F:推 CriLit:试试看先拿掉KERN_DEBUG 05/30 14:15