开发者社区> 问答> 正文

linux2.6内核编译报错

做操作系统内核编译模块实验遇到的问题。

Makefile
 ifneq ($(KERNELRELEASE),)
# We were called by kbuild
obj-m += clock.o
else  # We were called from command line
KDIR := /lib/modules/$(shell uname -r)/build
#KDIR := /home/cynove/src/kernel/linux-source-2.6.31
PWD  := $(shell pwd)

default:
    @echo '    Building target module 2.6 kernel.'
    @echo '    PLEASE IGNORE THE "Overriding SUBDIRS" WARNING'
    $(MAKE) -C $(KDIR) SUBDIRS=$(PWD) modules
install:
    ./do_install.sh *.ko
endif  # End kbuild check
######################### Version independent targets ##########################
clean:
    rm -f -r *.o *.ko .*cmd .tmp* core *.i
clock.c文件
 #include <linux/module.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/time.h>

#define BUF_LEN 100

static int read_clock(  char *buf_not_used,
char **my_buf_ptr,
off_t offset,
int buf_len,
int  *eof_flag,
void *data_not_used )
{
    struct timeval ktv;
    static char my_buf[BUF_LEN];    
    if(offset > 0) return 0;
    buf_len = BUF_LEN;
    *my_buf_ptr = my_buf;
    cli();
    ktv = xtime;    
    sti();

    sprintf(my_buf, "%ld %ld\n", ktv.tv_sec, ktv.tv_usec);
    for(buf_len=0; buf_len < BUF_LEN; buf_len++)
        if(my_buf[buf_len] == '\0') break;
            eof_flag = 0;
    return buf_len;
}
/*开始下面的结构定义不对*/
struct proc_dir_entry clock_proc_file = {
namelen:    5,
name:   "clock",
mode:   S_IFREG | S_IRUGO,
size:   100,
owner:  THIS_MODULE,
read_proc:  read_clock,
};

int init_clock(void)
{
    //return proc_register(&proc_root, &clock_proc_file);
    create_proc_read_entry("clock",0,NULL,read_clock,NULL);
    return 0;
}

void exit_clock(void)
{
    //proc_unregister(&proc_root, clock_proc_file.low_ino);
    remove_proc_entry("clock",&proc_root);
}
module_init(init_clock)
module_exit(exit_clock)
MODULE_LICENSE("GPL");  /*主要是为了去掉加载的时候的一个警告*/
编译时报错
[root@hadoop01 ~]# make
Building target module 2.6 kernel.
PLEASE IGNORE THE "Overriding SUBDIRS" WARNING
make -C /lib/modules/2.6.32-358.el6.x86_64/build SUBDIRS=/root modules
make[1]: Entering directory /usr/src/kernels/2.6.32-358.el6.x86_64'
CC [M] /root/clock.o
/root/clock.c: In function ‘read_clock’:
/root/clock.c:20: error: implicit declaration of function ‘cli’
/root/clock.c:21: error: ‘xtime’ undeclared (first use in this function)
/root/clock.c:21: error: (Each undeclared identifier is reported only once
/root/clock.c:21: error: for each function it appears in.)
/root/clock.c:22: error: implicit declaration of function ‘sti’
/root/clock.c: At top level:
/root/clock.c:36: error: unknown field ‘owner’ specified in initializer
/root/clock.c:36: warning: initialization from incompatible pointer type
/root/clock.c: In function ‘exit_clock’:
/root/clock.c:50: error: ‘proc_root’ undeclared (first use in this function)
make[2]: *** [/root/clock.o] Error 1
make[1]: *** [_module_/root] Error 2
make[1]: Leaving directory/usr/src/kernels/2.6.32-358.el6.x86_64'
make: *** [default] Error 2

原因可能是因为我的linux内核版本是2.6的,我看论坛上其他人的2.4内核可以正常编译。请问我要如何修改程序来适配2.6的内核?

展开
收起
杨冬芳 2016-07-18 14:56:50 2816 0
1 条回答
写回答
取消 提交回答
问答分类:
问答标签:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Alibaba Cloud Linux 3 发布 立即下载
ECS系统指南之Linux系统诊断 立即下载
ECS运维指南 之 Linux系统诊断 立即下载