LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1213|回复: 6

我的hello驱动怎么老是编译不了,苦恼了好久

[复制链接]
发表于 2006-9-6 21:29:11 | 显示全部楼层 |阅读模式
#include <linux/config.h>
#include <linux/module.h>
module_license("gpl");
#include <linux/kernel.h>
static int hello_init(const char *name,struct module *image)
{
        printk("hello,world\n");
        return 0;
}
static void hello_exit(void)
{
        printk("bye!\n");
}
module_init(hello_init);
module_exit(hello_exit);
 楼主| 发表于 2006-9-6 21:30:05 | 显示全部楼层

报错如下

In file included from /usr/include/linux/cpumask.h:8,
                 from /usr/include/linux/sched.h:15,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/linux/bitmap.h: In function `bitmap_empty':
/usr/include/linux/bitmap.h:15: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h:15: error: (Each undeclared identifier is reported only once
/usr/include/linux/bitmap.h:15: error: for each function it appears in.)
/usr/include/linux/bitmap.h: In function `bitmap_full':
/usr/include/linux/bitmap.h:29: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_equal':
/usr/include/linux/bitmap.h:44: error: `BITS_PER_LONG' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_shift_right':
/usr/include/linux/bitmap.h:85: error: `__shr_tmp' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_shift_left':
/usr/include/linux/bitmap.h:98: error: `__shl_tmp' undeclared (first use in this function)
/usr/include/linux/bitmap.h: In function `bitmap_weight':
/usr/include/linux/bitmap.h:144: error: `BITS_PER_LONG' undeclared (first use in this function)
In file included from /usr/include/linux/sched.h:15,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/linux/cpumask.h: At top level:
/usr/include/linux/cpumask.h:15: error: variable-size type declared outside of any function
In file included from /usr/include/linux/sched.h:15,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/linux/cpumask.h: In function `next_online_cpu':
/usr/include/linux/cpumask.h:56: error: structure has no member named `val'
In file included from /usr/include/linux/sched.h:21,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/asm/mmu.h: At top level:
/usr/include/asm/mmu.h:13: error: field `sem' has incomplete type
In file included from /usr/include/asm/smp.h:16,
                 from /usr/include/linux/smp.h:17,
                 from /usr/include/linux/sched.h:23,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/asm/fixmap.h:72: error: `FIX_ACPI_PAGES' undeclared here (not in a function)
/usr/include/asm/fixmap.h:72: error: enumerator value for `FIX_ACPI_END' not integer constant
/usr/include/asm/fixmap.h:84: error: parse error before "pgprot_t"
In file included from /usr/include/asm/smp.h:18,
                 from /usr/include/linux/smp.h:17,
                 from /usr/include/linux/sched.h:23,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/asm/mpspec.h:6:25: mach_mpspec.h: No such file or directory
In file included from /usr/include/asm/smp.h:18,
                 from /usr/include/linux/smp.h:17,
                 from /usr/include/linux/sched.h:23,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/asm/mpspec.h:8: error: `MAX_MP_BUSSES' undeclared here (not in a function)
/usr/include/asm/mpspec.h:9: error: `MAX_MP_BUSSES' undeclared here (not in a function)
/usr/include/asm/mpspec.h:10: error: `MAX_MP_BUSSES' undeclared here (not in a function)
/usr/include/asm/mpspec.h:12: error: `MAX_MP_BUSSES' undeclared here (not in a function)
/usr/include/asm/mpspec.h:19: error: `MAX_APICS' undeclared here (not in a function)
/usr/include/asm/mpspec.h:20: error: `MAX_MP_BUSSES' undeclared here (not in a function)
/usr/include/asm/mpspec.h:20: error: conflicting types for `mp_bus_id_to_type'
/usr/include/asm/mpspec.h:8: error: previous declaration of `mp_bus_id_to_type'
/usr/include/asm/mpspec.h:22: error: `MAX_IRQ_SOURCES' undeclared here (not in a function)
/usr/include/asm/mpspec.h:24: error: `MAX_MP_BUSSES' undeclared here (not in a function)
/usr/include/asm/mpspec.h:24: error: conflicting types for `mp_bus_id_to_pci_bus'
/usr/include/asm/mpspec.h:12: error: previous declaration of `mp_bus_id_to_pci_bus'
/usr/include/asm/mpspec.h:35: error: parse error before "id"
/usr/include/asm/mpspec.h:36: error: parse error before "address"
/usr/include/asm/mpspec.h:37: error: parse error before "id"
/usr/include/asm/mpspec.h:38: error: parse error before "bus_irq"
/usr/include/asm/mpspec.h:54: error: `MAX_APICS' undeclared here (not in a function)
/usr/include/asm/mpspec.h:54: error: variable-size type declared outside of any function
In file included from /usr/include/asm/smp.h:20,
                 from /usr/include/linux/smp.h:17,
                 from /usr/include/linux/sched.h:23,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/asm/io_apic.h:26: error: parse error before "u32"
/usr/include/asm/io_apic.h:28: error: parse error before "u32"
/usr/include/asm/io_apic.h:34: error: parse error before '}' token
/usr/include/asm/io_apic.h:37: error: parse error before "u32"
/usr/include/asm/io_apic.h:39: error: parse error before "u32"
/usr/include/asm/io_apic.h:45: error: parse error before '}' token
/usr/include/asm/io_apic.h:48: error: parse error before "u32"
/usr/include/asm/io_apic.h:50: error: parse error before "u32"
/usr/include/asm/io_apic.h:54: error: parse error before '}' token
/usr/include/asm/io_apic.h:57: error: parse error before "u32"
/usr/include/asm/io_apic.h:59: error: parse error before "u32"
/usr/include/asm/io_apic.h:62: error: parse error before '}' token
/usr/include/asm/io_apic.h:120: error: `MAX_IRQ_SOURCES' undeclared here (not in a function)
/usr/include/asm/io_apic.h:120: error: conflicting types for `mp_irqs'
/usr/include/asm/mpspec.h:22: error: previous declaration of `mp_irqs'
In file included from /usr/include/linux/smp.h:17,
                 from /usr/include/linux/sched.h:23,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/asm/smp.h:73:26: mach_apicdef.h: No such file or directory
In file included from /usr/include/linux/sched.h:23,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/linux/smp.h: In function `on_each_cpu':
/usr/include/linux/smp.h:65: error: invalid type argument of `->'
/usr/include/linux/smp.h:68: error: invalid type argument of `->'
/usr/include/linux/smp.h:68: error: `TIF_NEED_RESCHED' undeclared (first use in this function)
In file included from /usr/include/linux/signal.h:6,
                 from /usr/include/linux/sched.h:25,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/asm/signal.h: At top level:
/usr/include/asm/signal.h:29: error: conflicting types for `sigset_t'
/usr/include/sys/select.h:38: error: previous declaration of `sigset_t'
In file included from /usr/include/linux/sched.h:29,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/linux/completion.h:15: error: parse error before "wait_queue_head_t"
/usr/include/linux/completion.h: In function `init_completion':
/usr/include/linux/completion.h:26: error: dereferencing pointer to incomplete type
/usr/include/linux/completion.h:27: error: dereferencing pointer to incomplete type
In file included from /usr/include/linux/sched.h:30,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/linux/pid.h: At top level:
/usr/include/linux/pid.h:18: error: field `task_list' has incomplete type
/usr/include/linux/pid.h:19: error: field `hash_chain' has incomplete type
/usr/include/linux/pid.h:24: error: field `pid_chain' has incomplete type
In file included from /usr/include/linux/sched.h:102,
                 from /usr/include/linux/module.h:10,
                 from hello.c:2:
/usr/include/linux/timer.h:11: error: field `entry' has incomplete type
In file included from hello.c:2:
/usr/include/linux/module.h:190: error: field `list' has incomplete type
hello.c:3: error: parse error before string constant
hello.c:3: warning: data definition has no type or storage class
hello.c:14: warning: parameter names (without types) in function declaration
hello.c:14: warning: data definition has no type or storage class
hello.c:15: warning: parameter names (without types) in function declaration
hello.c:15: warning: data definition has no type or storage class
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-6 21:33:42 | 显示全部楼层

我的makefile如下

obj-m:=hello.o
make -c /usr/src/linux- 2.6.8 SUBDIRS=$PWD modules
回复 支持 反对

使用道具 举报

 楼主| 发表于 2006-9-6 21:34:31 | 显示全部楼层
make: *** No targets.  Stop.
make报错如上
回复 支持 反对

使用道具 举报

发表于 2006-9-6 21:45:18 | 显示全部楼层
这个文件可以编译,你研究看看问题在什么地方:
jiffies6.c
[PHP]
/*
*  Jiffies/jiffies6.c
*
*  Copyright (C) 2004 Jian Shen <shenjian@net.pku.edu.cn>
*
*  print jiffies at /proc/jiffies, in kernel 2.6
*/

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/proc_fs.h>
#include <linux/init.h>
#include <linux/times.h>

#define BUF_LEN 20

int jiffies_read(char* sys_buffer,
                                  char** my_buffer,
                                  off_t offset,
                                  int buffer_length,
                                  int *eof,
                                  void* data)
{
        int len;
        static char buf[BUF_LEN];

        if(offset > 0)
                return 0;

        len = sprintf(buf, "%llu\n", jiffies_64_to_clock_t(get_jiffies_64() - INITIAL_JIFFIES));

        *my_buffer = buf;

        return len;
}

int jiffies_module_init()
{
        struct proc_dir_entry *entry;

    /* Create the entry in the proc filesystem */
    printk("hello world.");
    entry = create_proc_entry("jiffies", 0444, &proc_root);
    if(entry == 0) {
                printk(KERN_ERR "create_proc_entry failed.\n");
        return -1;
        }

    /* File permissions, size, and the read function */
    entry->mode = S_IFREG | 0444;
    entry->size = 0;
    entry->read_proc = jiffies_read;

    return 0;
}

void jiffies_module_cleanup()
{
        remove_proc_entry("jiffies", &proc_root);
            printk("hello world,end.");
}


MODULE_LICENSE("GPL");
MODULE_AUTHOR("Shen Jian <shenjian@net.pku.edu.cn");

module_init(jiffies_module_init);
module_exit(jiffies_module_cleanup);


[/PHP]

Makefile文件
[PHP]
TARGET = prjiff

KERNELDIR = /lib/modules/`uname -r`/build
PWD = $(shell pwd)

obj-m += $(TARGET).o
$(TARGET)-objs := jiffies6.o

modules:
        make -C $(KERNELDIR) SUBDIRS=$(PWD) modules

install:
        install ./$(TARGET).ko /usr/local/lib
        /sbin/insmod ./$(TARGET).ko

uninstall:
        rm -f /usr/local/lib/$(TARGET).ko
        /sbin/rmmod $(TARGET)

clean:
        rm -f *.o *.ko *.mod.c

[/PHP]
回复 支持 反对

使用道具 举报

发表于 2006-9-7 08:40:34 | 显示全部楼层
回复 支持 反对

使用道具 举报

发表于 2006-9-7 09:51:11 | 显示全部楼层
对应你使用的内核的源代码头文件没有装
apt-get install linux-headers-2. 6.*  //你用的内核版本号对应的头文件
make file
KERNELDIR = /usr/src/linux-headers-2.6***
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表