アプリ版:「スタンプのみでお礼する」機能のリリースについて

こんにちは
LKMの作成で躓いているのでお力をお貸しください

OS: Debian4.0 r6
kernel: 2.6.18-6-686
GCC: 4.1.2

[ソース: message.c]
#include <linux/module.h>
#include <kernel.h>
#include <linux/init.h>

static int __init init_module(void)
{
printk(KERN_INFO "loaded\n");
return 0;
}

static void __exit cleanup_module(void)
{
printk(KERN_INFO "removed\n");
}

module_init(init_module);
module_exit(cleanup_module);

[コンパイル結果]
make -C /lib/modules/2.6.18-6-686/build M=/home/user/lkm modules
make[1]: ディレクトリ `/usr/src/linux-headers-2.6.18-6-686' に入ります
CC [M] /home/user/lkm/message.o
/home/user/lkm/message.c:6: error: static declaration of 'init_module' follows non-static declaration
include/linux/module.h:65: error: previous declaration of 'init_module' was here
/home/user/lkm/message.c:12: error: static declaration of 'cleanup_module' follows non-static declaration
include/linux/module.h:66: error: previous declaration of 'cleanup_module' was here
/home/user/lkm/message.c:16: error: redefinition of 'init_module'
/home/user/lkm/message.c:6: error: previous definition of 'init_module' was here
/home/user/lkm/message.c:17: error: redefinition of 'cleanup_module'
/home/user/lkm/message.c:12: error: previous definition of 'cleanup_module' was here
make[2]: *** [/home/user/lkm/message.o] エラー 1
make[1]: *** [_module_/home/user/lkm] エラー 2
make[1]: ディレクトリ `/usr/src/linux-headers-2.6.18-6-686' から出ます
make: *** [default] エラー 2

初歩的な質問で申し訳ないですが
エラー冒頭のstatic declaration of ...というエラーが直せなくて困っております。
どなたかお分かりになる方、お力をお貸しください
宜しくお願いします。

A 回答 (1件)

関数の名前の付け方が悪いです。


init_module,cleanup_moduleはlsmod,rmmodの時に呼び出される関数ですので別の名前をつけましょう。
init_module_aaa, cleanup_module_aaa などすればコンパイルが通るようになります。(もっときちんした名前をつけるべきですが‥‥)

また、<linux/init.h>を使わずに
int init_module(void)
{
}
void cleanup_module(void)
{
}
と書くこともできます。
    • good
    • 0
この回答へのお礼

ありがとうございました。
無事コンパイルが通るようになりました。

お礼日時:2009/01/23 23:20

お探しのQ&Aが見つからない時は、教えて!gooで質問しましょう!