0

I am trying to write a simple kernel driver,but i find some prolems that i can't solve it.Follow,

wordc.c:

#include <linux/module.h>
#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/fs.h>
#include <linux/miscdevice.h>
#include <asm/uaccess.h>

static int word_count_init(void)
   {
    printk("word_count_init_success\n");
    return 0;
}
//退出Linux驱动
static void word_count_exit(void)
{
  printk("word_count_exit_success\n");
}

// 注册初始化Linux驱动的函数
module_init(word_count_init);
// 注册推出Linux驱动的函数
module_exit(word_count_exit);

MODULE_LICENSE("GPL");

Makefile:

    ifneq ($(KERNELRELEASE),)
  obj-m := wordc.o
else
  KERNELDIR := /lib/modules/$(shell uname -r)/build
  PWD :=  $(shell pwd)
default:
  $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
  rm -f *.o *.mod.c *.mod.o *.ko
endif

when i try to make it,it display

 make: Entering directory `/usr/src/linux-headers-3.11.0-20-generic'
  LD      /android_src/drivers/ch06/built-in.o
  CC [M]  /android_src/drivers/ch06/wordc.o
  Building modules, stage 2.
  MODPOST 1 modules
WARNING: "mcount" [/android_src/drivers/ch06/wordc.ko] undefined!
  CC      /android_src/drivers/ch06/wordc.mod.o
  LD [M]  /android_src/drivers/ch06/wordc.ko
make: Leaving directory `/usr/src/linux-headers-3.11.0-20-generic'

the warning "mcount",anyone can tell me how to solve it.ths. and then,i use "insmod wordc.ko",i failed,

insmod: error inserting 'wordc.ko': -1 Unknown symbol in module

1 Answers1

0

I think i had found the problem and solved it. the reason came from the edition of GCC. My gcc edition was 4.4.7,when i changed it to 4.8, all problems had dismissed.