你好,游客 登录 注册 搜索
背景:
阅读新闻

Linux 多个文件.c 一个模块

[日期:2010-12-28] 来源:Linux社区  作者:zengzhaonong [字体:大 中 小]

test.h
--------------------------------------------
#define BUF_SIZE 100

typedef struct {
    void * base_addr;
    int    buf_size;
} buf_info;

extern buf_info skb_info;
void init_buf(buf_info * skb_info);

test.c
--------------------------------------------
#include "test.h"
buf_info skb_info;

void init_buf(buf_info * skb_info)
{
    skb_info->base_addr = 0;
    skb_info->buf_size  = BUF_SIZE;
}

hello.c
--------------------------------------------
#include <linux/module.h> 
#include <linux/kernel.h>
#include <asm/param.h>
#include "test.h"

static int __init hello_init(void)
{
    printk("<1>Hello world 1.\n");
    printk("<1>HZ = %d\n", HZ);
    init_buf(&skb_info);
    return 0;
}

static void __exit hello_exit(void)
{
    printk(KERN_ALERT "Goodbye world 1.\n");
}

module_init(hello_init);
module_exit(hello_exit);

MODULE_LICENSE("GPL");
MODULE_AUTHOR("zengxiaolong ");
MODULE_DESCRIPTION("A sample driver");
MODULE_SUPPORTED_DEVICE("testdevice");

Makefile
--------------------------------------------
KERNEL_LOCATION := /home/zengxiaolong/soft/s3c2410/linux-2.6.24
obj-m += helloworld.o
helloworld-y += hello.o
helloworld-y += test.o


all:
    make -C $(KERNEL_LOCATION) M=`pwd` modules
clean:
    make -C $(KERNEL_LOCATION) M=`pwd` clean

linux
相关资讯       Linux编程 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款