作者 主題: linux 驅動程式 3/e書上的範例  (閱讀 8148 次)

0 會員 與 1 訪客 正在閱讀本文。

shihyu

  • 活潑的大學生
  • ***
  • 文章數: 223
    • 檢視個人資料
linux 驅動程式 3/e書上的範例
« 於: 2006-09-08 22:53 »
代碼: [選擇]


#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
        printk(KERN_ALERT "Hello, world\n");
        return 0;
}
static void hello_exit(void)
{

        printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);




這是linux 驅動程式 3/e 中的範例 ....
我用gcc 直接編譯不可以編譯成功 .. 請問要編譯這是不是需要安裝什麼模組之類的???

謝謝

Darkhero

  • 酷!學園 學長們
  • 俺是博士!
  • *****
  • 文章數: 3728
  • 性別: 男
    • 檢視個人資料
    • ㄚ凱隨手紀
Re: linux 驅動程式 3/e書上的範例
« 回覆 #1 於: 2006-09-09 08:44 »
引述: "shihyu"
代碼: [選擇]


#include <linux/init.h>
#include <linux/module.h>
MODULE_LICENSE("Dual BSD/GPL");

static int hello_init(void)
{
        printk(KERN_ALERT "Hello, world\n");
        return 0;
}
static void hello_exit(void)
{

        printk(KERN_ALERT "Goodbye, cruel world\n");
}

module_init(hello_init);
module_exit(hello_exit);




這是linux 驅動程式 3/e 中的範例 ....
我用gcc 直接編譯不可以編譯成功 .. 請問要編譯這是不是需要安裝什麼模組之類的???

謝謝


直接編譯不成功,那請問你有看到錯誤訊息嗎?...

還是要大家都拷貝您貼的原始碼自己編譯一次才知道是什麼錯誤訊息?...
希望我們的討論是為了把問題解決,而不是爭論誰對誰錯.
『灌水才是重點,發文只是順便』
『我寧可讓不會釣魚的工程師餓死,也不想讓會餓死的工程師去攪沉公司....』
Blog: http://blog.darkhero.net/
秘密基地: http://www.darkhero.net/comic/
目前服務的網站: http://www.libook.com.tw/

shihyu

  • 活潑的大學生
  • ***
  • 文章數: 223
    • 檢視個人資料
linux 驅動程式 3/e書上的範例
« 回覆 #2 於: 2006-09-09 13:46 »
代碼: [選擇]


/usr/include/linux/nodemask.h: In function '__nodes_weight':
/usr/include/linux/nodemask.h:201: error: 'srcp' undeclared (first use in this function)
/usr/include/linux/nodemask.h:201: error: 'nbits' undeclared (first use in this function)
/usr/include/linux/nodemask.h: At top level:
/usr/include/linux/nodemask.h:206: error: syntax error before '*' token
/usr/include/linux/nodemask.h: In function '__nodes_shift_right':
/usr/include/linux/nodemask.h:209: error: 'dstp' undeclared (first use in this function)
/usr/include/linux/nodemask.h:209: error: 'srcp' undeclared (first use in this function)
/usr/include/linux/nodemask.h:209: error: 'n' undeclared (first use in this function)
/usr/include/linux/nodemask.h:209: error: 'nbits' undeclared (first use in this function)
/usr/include/linux/nodemask.h: At top level:
/usr/include/linux/nodemask.h:214: error: syntax error before '*' token
/usr/include/linux/nodemask.h: In function '__nodes_shift_left':
/usr/include/linux/nodemask.h:217: error: 'dstp' undeclared (first use in this function)
/usr/include/linux/nodemask.h:217: error: 'srcp' undeclared (first use in this function)
/usr/include/linux/nodemask.h:217: error: 'n' undeclared (first use in this function)
/usr/include/linux/nodemask.h:217: error: 'nbits' undeclared (first use in this function)
/usr/include/linux/nodemask.h: At top level:
/usr/include/linux/nodemask.h:224: error: syntax error before '*' token
/usr/include/linux/nodemask.h: In function '__first_node':
/usr/include/linux/nodemask.h:226: error: syntax error before 'int'
/usr/include/linux/nodemask.h: At top level:
/usr/include/linux/nodemask.h:230: error: syntax error before '*' token
/usr/include/linux/nodemask.h: In function '__next_node':
/usr/include/linux/nodemask.h:232: error: syntax error before 'int'
/usr/include/linux/nodemask.h: At top level:
/usr/include/linux/nodemask.h:248: error: syntax error before '*' token
/usr/include/linux/nodemask.h: In function '__first_unset_node':
/usr/include/linux/nodemask.h:250: error: syntax error before 'int'
/usr/include/linux/nodemask.h: At top level:
/usr/include/linux/nodemask.h:283: error: syntax error before '*' token
/usr/include/linux/nodemask.h: In function '__nodemask_scnprintf':
/usr/include/linux/nodemask.h:285: error: 'buf' undeclared (first use in this function)
/usr/include/linux/nodemask.h:285: error: 'len' undeclared (first use in this function)
/usr/include/linux/nodemask.h:285: error: 'srcp' undeclared (first use in this function)
/usr/include/linux/nodemask.h:285: error: 'nbits' undeclared (first use in this function)
/usr/include/linux/nodemask.h: At top level:
/usr/include/linux/nodemask.h:291: error: syntax error before 'nodemask_t'
/usr/include/linux/nodemask.h: In function '__nodemask_parse':
/usr/include/linux/nodemask.h:293: error: 'buf' undeclared (first use in this function)
/usr/include/linux/nodemask.h:293: error: 'len' undeclared (first use in this function)
/usr/include/linux/nodemask.h:293: error: 'dstp' undeclared (first use in this function)
/usr/include/linux/nodemask.h:293: error: 'nbits' undeclared (first use in this function)
/usr/include/linux/nodemask.h: At top level:
/usr/include/linux/nodemask.h:299: error: syntax error before '*' token
/usr/include/linux/nodemask.h: In function '__nodelist_scnprintf':
/usr/include/linux/nodemask.h:301: error: 'buf' undeclared (first use in this function)
/usr/include/linux/nodemask.h:301: error: 'len' undeclared (first use in this function)
/usr/include/linux/nodemask.h:301: error: 'srcp' undeclared (first use in this function)
/usr/include/linux/nodemask.h:301: error: 'nbits' undeclared (first use in this function)
/usr/include/linux/nodemask.h: At top level:
/usr/include/linux/nodemask.h:305: error: syntax error before 'nodemask_t'
/usr/include/linux/nodemask.h: In function '__nodelist_parse':
/usr/include/linux/nodemask.h:307: error: 'buf' undeclared (first use in this function)
/usr/include/linux/nodemask.h:307: error: 'dstp' undeclared (first use in this function)
/usr/include/linux/nodemask.h:307: error: 'nbits' undeclared (first use in this function)
/usr/include/linux/nodemask.h: At top level:
/usr/include/linux/nodemask.h:326: error: syntax error before 'node_online_map'
/usr/include/linux/nodemask.h:327: error: syntax error before 'node_possible_map'
In file included from /usr/include/asm/mmu.h:8,
                 from /usr/include/linux/sched.h:23,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/asm-i486/mmu.h:13: error: field 'sem' has incomplete type
In file included from /usr/include/asm-i486/cputime.h:4,
                 from /usr/include/asm/cputime.h:8,
                 from /usr/include/linux/sched.h:24,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/asm-generic/cputime.h:23: error: syntax error before 'cputime64_t'
In file included from /usr/include/asm/fixmap.h:8,
                 from /usr/include/asm-i486/smp.h:16,
                 from /usr/include/asm/smp.h:8,
                 from /usr/include/linux/smp.h:19,
                 from /usr/include/linux/sched.h:26,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/asm-i486/fixmap.h:81: error: 'FIX_ACPI_PAGES' undeclared here (not in a function)
/usr/include/asm-i486/fixmap.h:96: error: syntax error before 'pgprot_t'
In file included from /usr/include/asm/mpspec.h:8,
                 from /usr/include/asm-i486/smp.h:18,
                 from /usr/include/asm/smp.h:8,
                 from /usr/include/linux/smp.h:19,
                 from /usr/include/linux/sched.h:26,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/asm-i486/mpspec.h:6:25: error: mach_mpspec.h: 沒有此一檔案或目錄
In file included from /usr/include/asm/mpspec.h:8,
                 from /usr/include/asm-i486/smp.h:18,
                 from /usr/include/asm/smp.h:8,
                 from /usr/include/linux/smp.h:19,
                 from /usr/include/linux/sched.h:26,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/asm-i486/mpspec.h:8: error: 'MAX_MP_BUSSES' undeclared here (not in a function)
/usr/include/asm-i486/mpspec.h:22: error: 'MAX_IRQ_SOURCES' undeclared here (not in a function)
/usr/include/asm-i486/mpspec.h:30: error: syntax error before 'id'
/usr/include/asm-i486/mpspec.h:31: error: syntax error before 'address'
/usr/include/asm-i486/mpspec.h:32: error: syntax error before 'id'
/usr/include/asm-i486/mpspec.h:33: error: syntax error before 'bus_irq'
/usr/include/asm-i486/mpspec.h:35: error: syntax error before 'gsi'
/usr/include/asm-i486/mpspec.h:42: error: variably modified 'mask' at file scope
In file included from /usr/include/asm/io_apic.h:8,
                 from /usr/include/asm-i486/smp.h:20,
                 from /usr/include/asm/smp.h:8,
                 from /usr/include/linux/smp.h:19,
                 from /usr/include/linux/sched.h:26,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/asm-i486/io_apic.h:64: error: syntax error before 'u32'
/usr/include/asm-i486/io_apic.h:66: error: syntax error before 'u32'
/usr/include/asm-i486/io_apic.h:72: error: syntax error before '}' token
/usr/include/asm-i486/io_apic.h:75: error: syntax error before 'u32'
/usr/include/asm-i486/io_apic.h:77: error: syntax error before 'u32'
/usr/include/asm-i486/io_apic.h:83: error: syntax error before '}' token
/usr/include/asm-i486/io_apic.h:86: error: syntax error before 'u32'
/usr/include/asm-i486/io_apic.h:88: error: syntax error before 'u32'
/usr/include/asm-i486/io_apic.h:92: error: syntax error before '}' token
/usr/include/asm-i486/io_apic.h:95: error: syntax error before 'u32'
/usr/include/asm-i486/io_apic.h:97: error: syntax error before 'u32'
/usr/include/asm-i486/io_apic.h:100: error: syntax error before '}' token
In file included from /usr/include/asm/smp.h:8,
                 from /usr/include/linux/smp.h:19,
                 from /usr/include/linux/sched.h:26,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/asm-i486/smp.h:37: error: syntax error before 'cpu_sibling_map'
/usr/include/asm-i486/smp.h:38: error: syntax error before 'cpu_core_map'
/usr/include/asm-i486/smp.h:49: error: syntax error before 'x86_cpu_to_apicid'
/usr/include/asm-i486/smp.h:63: error: syntax error before 'cpu_callout_map'
/usr/include/asm-i486/smp.h:64: error: syntax error before 'cpu_callin_map'
In file included from /usr/include/asm/smp.h:8,
                 from /usr/include/linux/smp.h:19,
                 from /usr/include/linux/sched.h:26,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/asm-i486/smp.h:78:26: error: mach_apicdef.h: 沒有此一檔案或目錄
In file included from /usr/include/linux/sched.h:26,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/linux/smp.h: In function 'on_each_cpu':
/usr/include/linux/smp.h:67: error: invalid type argument of '->'
/usr/include/linux/smp.h:70: error: invalid type argument of '->'
/usr/include/linux/smp.h:70: error: 'TIF_NEED_RESCHED' undeclared (first use in this function)
In file included from /usr/include/asm/signal.h:8,
                 from /usr/include/linux/signal.h:6,
                 from /usr/include/linux/sched.h:28,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/asm-i486/signal.h: At top level:
/usr/include/asm-i486/signal.h:30: error: conflicting types for 'sigset_t'
/usr/include/sys/select.h:38: error: previous declaration of 'sigset_t' was here
In file included from /usr/include/linux/sched.h:32,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/linux/completion.h:15: error: syntax 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:33,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/linux/pid.h: At top level:
/usr/include/linux/pid.h:17: error: field 'pid_chain' has incomplete type
/usr/include/linux/pid.h:19: error: field 'pid_list' has incomplete type
In file included from /usr/include/linux/sched.h:36,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/linux/seccomp.h: In function 'secure_computing':
/usr/include/linux/seccomp.h:18: error: 'TIF_SECCOMP' undeclared (first use in this function)
/usr/include/linux/seccomp.h: In function 'has_secure_computing':
/usr/include/linux/seccomp.h:24: error: 'TIF_SECCOMP' undeclared (first use in this function)
In file included from /usr/include/linux/sched.h:104,
                 from /usr/include/linux/module.h:10,
                 from ldd.c:4:
/usr/include/linux/timer.h: At top level:
/usr/include/linux/timer.h:12: error: field 'entry' has incomplete type
In file included from ldd.c:4:
/usr/include/linux/module.h:50: error: field 'attr' has incomplete type
/usr/include/linux/module.h:61: error: field 'kobj' has incomplete type
/usr/include/linux/module.h:226: error: field 'grp' has incomplete type
/usr/include/linux/module.h:237: error: field 'list' has incomplete type
ldd.c: In function 'hello_init':
ldd.c:9: error: 'KERN_ALERT' undeclared (first use in this function)
ldd.c:9: error: syntax error before string constant
ldd.c: In function 'hello_exit':
ldd.c:15: error: 'KERN_ALERT' undeclared (first use in this function)
ldd.c:15: error: syntax error before string constant



錯誤訊息

hsinan

  • 懷疑的國中生
  • **
  • 文章數: 66
    • 檢視個人資料
linux 驅動程式 3/e書上的範例
« 回覆 #3 於: 2006-09-09 15:20 »
You may try to change your header files to any suitbale one not the default header files, or it may depend on different Linux platform or change your environmanet variable to different location instead of this default location, or something else. At least check what/where it included from first.