编译内核模块的问题
发表于 : 2008-06-18 12:13
大家好,我写了一个内核模块的helloworld程序,以演示这个问题。
以下程序我实验过。
//helloworld.c
#include <linux/module.h>
#include "rel.h"
int init_module(void)
{
printk("<1> Hello World!\n");
p("abc");
return 0;
}
void cleanup_module(void)
{
printk("<1> Goodbye!\n");
}
MODULE_LICENSE("GPL");
//--------------------------------------------------------
//rel.c
#include "rel.h"
#include <linux/module.h>
void p(char *ch)
{
printk("%s\n", ch);
}
//--------------------------------------------------------
//rel.h
#ifndef _REL_H_
#define _REL_H_
void p(char*ch);
#endif
//--------------------------------------------------------
//Makefile
obj-m+=helloworld.o
obj-m+=rel.o
KERNEL_DIR:=/lib/modules/$(shell uname -r)/build
PWD:=$(shell pwd)
all:
make -C $(KERNEL_DIR) M=$(PWD) modules
clean:
rm *.o *.ko
//--------------------------------------------------------
编译之后显示这个问题:
[root@localhost module]# make
make -C /lib/modules/2.6.23.1-42.fc8/build M=/home/zongzw/实例程序/module modules
make[1]: Entering directory `/usr/src/kernels/2.6.23.1-42.fc8-i686'
Building modules, stage 2.
MODPOST 2 modules
WARNING: "p" [/home/zongzw/实例程序/module/helloworld.ko] undefined!
make[1]: Leaving directory `/usr/src/kernels/2.6.23.1-42.fc8-i686'
该如何解决呢,看到网上有很多人碰到这个问题,但是没有看到解决方案。。。
就是在说我自己实现的这个p函数没有定义。该如何是好?
谢谢了。
以下程序我实验过。
//helloworld.c
#include <linux/module.h>
#include "rel.h"
int init_module(void)
{
printk("<1> Hello World!\n");
p("abc");
return 0;
}
void cleanup_module(void)
{
printk("<1> Goodbye!\n");
}
MODULE_LICENSE("GPL");
//--------------------------------------------------------
//rel.c
#include "rel.h"
#include <linux/module.h>
void p(char *ch)
{
printk("%s\n", ch);
}
//--------------------------------------------------------
//rel.h
#ifndef _REL_H_
#define _REL_H_
void p(char*ch);
#endif
//--------------------------------------------------------
//Makefile
obj-m+=helloworld.o
obj-m+=rel.o
KERNEL_DIR:=/lib/modules/$(shell uname -r)/build
PWD:=$(shell pwd)
all:
make -C $(KERNEL_DIR) M=$(PWD) modules
clean:
rm *.o *.ko
//--------------------------------------------------------
编译之后显示这个问题:
[root@localhost module]# make
make -C /lib/modules/2.6.23.1-42.fc8/build M=/home/zongzw/实例程序/module modules
make[1]: Entering directory `/usr/src/kernels/2.6.23.1-42.fc8-i686'
Building modules, stage 2.
MODPOST 2 modules
WARNING: "p" [/home/zongzw/实例程序/module/helloworld.ko] undefined!
make[1]: Leaving directory `/usr/src/kernels/2.6.23.1-42.fc8-i686'
该如何解决呢,看到网上有很多人碰到这个问题,但是没有看到解决方案。。。
就是在说我自己实现的这个p函数没有定义。该如何是好?
谢谢了。