[Debian]LKMの作成について

このQ&Aのポイント
  • Debian4.0 r6のOSでLKMの作成につまずいています。エラーの内容としては、'static declaration of ...'というエラーが出ています。
  • エラーの原因が特定できず、対処方法に困っています。解決策をお知りの方、ご教授ください。
  • Debian4.0 r6のOSでLKMの作成に関するエラーの解決策を教えてください。エラー内容は'static declaration of ...'です。
回答を見る
  • ベストアンサー

[Debian]LKMの作成について

こんにちは 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 ...というエラーが直せなくて困っております。 どなたかお分かりになる方、お力をお貸しください 宜しくお願いします。

質問者が選んだベストアンサー

  • ベストアンサー
noname#136147
noname#136147
回答No.1

関数の名前の付け方が悪いです。 init_module,cleanup_moduleはlsmod,rmmodの時に呼び出される関数ですので別の名前をつけましょう。 init_module_aaa, cleanup_module_aaa などすればコンパイルが通るようになります。(もっときちんした名前をつけるべきですが‥‥) また、<linux/init.h>を使わずに int init_module(void) { } void cleanup_module(void) { } と書くこともできます。

ftdr5v6bn
質問者

お礼

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

関連するQ&A

  • libxml2 make 失敗

    CentOS-6.2で開発用のAPサーバを構築中です。 「libxml2」をmake install したいのですが、makeが上手くいっていないように思います。 「libxml2-2.6.26」が現在インストールされているのですが、「libxml2-2.6.30」を導入しようとしています。色々調べて実施しているのですが、ログを読み取れていないので苦戦しています。。 何が原因なのでしょうか。 以下に気になる箇所のログを記載しました。 よろしくお願いいたします。 ※補足 rpmでインストールも試したのですが、それも「依存性の欠如」エラーで上手くいかない状況です。 インストールされているのに「ない」とエラーが出たりです・・・ threads.c:57: warning: redundant redeclaration of 'pthread_once' /usr/include/pthread.h:466: warning: previous declaration of 'pthread_once' was here threads.c:59: warning: redundant redeclaration of 'pthread_getspecific' /usr/include/pthread.h:1076: warning: previous declaration of 'pthread_getspecific' was here threads.c:62: warning: redundant redeclaration of 'pthread_setspecific' /usr/include/pthread.h:1080: warning: previous declaration of 'pthread_setspecific' was here threads.c:65: warning: redundant redeclaration of 'pthread_key_create' /usr/include/pthread.h:1070: warning: previous declaration of 'pthread_key_create' was here threads.c:67: warning: function declaration isn't a prototype threads.c:67: warning: redundant redeclaration of 'pthread_mutex_init' /usr/include/pthread.h:720: warning: previous declaration of 'pthread_mutex_init' was here threads.c:69: warning: function declaration isn't a prototype threads.c:69: warning: redundant redeclaration of 'pthread_mutex_destroy' /usr/include/pthread.h:724: warning: previous declaration of 'pthread_mutex_destroy' was here threads.c:71: warning: function declaration isn't a prototype threads.c:71: warning: redundant redeclaration of 'pthread_mutex_lock' /usr/include/pthread.h:732: warning: previous declaration of 'pthread_mutex_lock' was here threads.c:73: warning: function declaration isn't a prototype threads.c:73: warning: redundant redeclaration of 'pthread_mutex_unlock' /usr/include/pthread.h:743: warning: previous declaration of 'pthread_mutex_unlock' was here threads.c:75: warning: function declaration isn't a prototype threads.c:75: warning: redundant redeclaration of 'pthread_cond_init' /usr/include/pthread.h:927: warning: previous declaration of 'pthread_cond_init' was here threads.c:77: warning: function declaration isn't a prototype threads.c:431: warning: unused variable 'err' testapi.c:17978: 警告: ‘gen_xmlSchematronPtr’ defined but not used testapi.c:17981: 警告: ‘des_xmlSchematronPtr’ defined but not used testapi.c:17998: 警告: ‘gen_xmlSchematronParserCtxtPtr’ defined but not used testapi.c:33930: 警告: ‘gen_xmlSAXHandlerPtr_ptr’ defined but not used testapi.c:33933: 警告: ‘des_xmlSAXHandlerPtr_ptr’ defined but not used make[3]: ディレクトリ `/home/myapp/libxml2-2.6.30/doc/examples' から出ます make[3]: ディレクトリ `/home/myapp/libxml2-2.6.30/doc' に入ります make[3]: `all-am' に対して行うべき事はありません. make[3]: ディレクトリ `/home/myapp/libxml2-2.6.30/doc' から出ます I/O error : Attempt to load network entity http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ../doc/news.html:2: warning: failed to load external entity "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" reating gjobread make[2]: ディレクトリ `/home/myapp/libxml2-2.6.30/example' から出ます Making all in xstc make[2]: ディレクトリ `/home/myapp/libxml2-2.6.30/xstc' に入ります make[2]: `all' に対して行うべき事はありません. make[2]: ディレクトリ `/home/myapp/libxml2-2.6.30/xstc' から出ます make[1]: ディレクトリ `/home/myapp/libxml2-2.6.30' から出ます

  • LKMを用いたカーネル2.6でのシステムコールのフック

    度々すみません。 LKMを使ったシステムコールのフックに挑戦しているのですがうまくいかずに悩んでいます。 お力を貸していただけたら嬉しいです。 ディストリビューション: Debian 4.0r4 カーネル: 2.6.24 以前2.6.18のカーネルを使っていたのですが、使用するカーネルのバージョンを上げました。 開発前にやったことをすべて書いておきます。 ・ linux-source-2.6.24_2.6.24-6~etchnhalf.7_all.deb ・ linux-headers-2.6.24-etchnhalf.1-686_2.6.24-6~etchnhalf.7_i386.deb ・ linux-kbuild-2.6.24-1~etchnhalf.1_i386.deb をダウンロードし、dpkg -i *.deb で展開。 /usr/src/linux-source-2.6.24/arch/x86/kernel/i386_ksyms_32.c の末尾に以下の2行を追加 extern void *sys_call_table[]; EXPORT_SYMBOL(sys_call_table); 変更後以下の手順でカーネルコンパイル cp /boot/config-2.6.18-6-686 .config make menuconfig (Enterを押しっぱなしにして設定終了) make-kpkg --initrd kernel_image dpkg -i (kernel_image).deb 書いたプログラムは以下です。 #include <linux/module.h> #include <linux/init.h> #include <linux/syscalls.h> #include <linux/utsname.h> #include <asm-x86/unistd_32.h> MODULE_LICENSE("GPL"); extern void *sys_call_table[]; static char *msg = "[message.o]:"; asmlinkage int (*orig_open)(const char *pathname, int flags); asmlinkage static int hook_open(const char *pathname, int flags) { printk(KERN_INFO "hook_open(\"%s\", %d)\n", pathname, flags); return orig_open(pathname, flags); } static int message_module(void) { printk(KERN_INFO "%s loaded\n",msg); printk(KERN_INFO "%s hook_init\n", msg); orig_open = sys_call_table[__NR_open]; sys_call_table[__NR_open] = hook_open; return 0; } static void message_remove(void) { printk(KERN_INFO "%s removed\n", msg); printk(KERN_INFO "%s hook_exit\n", msg); sys_call_table[__NR_open] = orig_open; } module_init(message_module); module_exit(message_remove); コンパイルすると以下のようなエラーが出ます。 user@debian:~/lkm/message$ make make -C /lib/modules/2.6.24/build M=/home/user/lkm/message modules make[1]: ディレクトリ `/usr/src/linux-source-2.6.24' に入ります Building modules, stage 2. MODPOST 1 modules WARNING: "sys_call_table" [/home/user/lkm/message/message.ko] undefined! make[1]: ディレクトリ `/usr/src/linux-source-2.6.24' から出ます 長文で申し訳ありませんが、お力をお貸しください。 宜しくお願いします。

  • 自作モジュールを組み込む

    以下に何もしない何もしないカーネルモジュールを組み込みたいのですが、うまくいきません。 以下のソースをコンパイルします。 #define MODULE #include <linux/module.h> #include <linux/kernel.h> int init_module(void) { printk("my module installed\n"); return 0; } void cleanup_module(void) { printk("my module removed\n"); } そして、コンパイル $gcc -c sample.c #insmod sample.o とすると、 insmod: error inserting 'sample.o': -1 Invalid module format と怒られてしまいます。 モジュールフォーマットが無効と言われますが、ソースが間違っているのでしょうか。 カーネルのメッセージを調べると、 $dmesg ... No module found in object と、やっぱり組み込まれていません。 何がいけないのか、御知恵をくださいお願いします。 追記: 自分の環境を以下に記載させていただきます。 Linux localhost.localdomain 2.6.11-1.1369_FC4 #1 Thu Jun 2 22:55:56 EDT 2005 i686 athlon i386 GNU/Linux

  • autorespond-2.0.2のインストール

    autorespond-2.0.2をインストールしようとしているのですが 下記のメッセージが出てインストール出来ない状態です。 ---- www# make gcc -Wall -o autorespond autorespond.c autorespond.c:381: conflicting types for `strcasestr' /usr/include/string.h:86: previous declaration of `strcasestr' *** Error code 1 Stop in /usr/local/src/autorespond-2.0.2. ---- どうすればいいかわからないのでアドバイスをお願いします。 OSはFreeBSD4.7です

  • Solaris10へsendmail8.12.10インストールができません。

    サーバ構築未熟者で、Solaris10の構築は初めての者です。 Solaris10へのsendmail8.12.10をインストールを試みておりますが、Build時にエラーが発生し、 インストールできない状態になっております。 エラー内容はこのようになっており、エラー内容から環境変数の一部の設定がおかしいのではないかと推測しております。 ../../include/sm/conf.h:2610: error: conflicting types for 'unsetenv' /usr/include/stdlib.h:188: error: previous declaration of 'unsetenv' was here ../../include/sm/conf.h:2610: error: conflicting types for 'unsetenv' /usr/include/stdlib.h:188: error: previous declaration of 'unsetenv' was here make[1]: *** [debug.o] Error 1 make[1]: Leaving directory `/usr/local/src/sendmail-8.12.10/obj.SunOS.5.10.i86pc 該当の部分と思われる、conf.hファイルの2610行目は、デフォルト状態です。 サーバ構築期限がさしせまっており、非常に困っております。 もしわかる方がいらっしゃいましたらアドバイスをお願いいたします。

  • linux/module.h インクルードできない

    もう自力ではわからず、検索しても解決できなかったので、わかる方、力を貸してください。 まず環境は Ubuntu 12.10 をVirtualBoxで動かしています。 そして、以下のパッケージをインストールしました。 linux-source-3.5.0 linux-header-3.5.0-19-generic その後、以下のソースをコンパイルしようとしました。 1 #include <linux/module.h> /* module 作成には必須 */ 2 #include <linux/kernel.h> /* printk */ 3 4 MODULE_LICENSE( "GPL" ); 5 6 static char* msg = "module [message.o]"; 7 8 9 /* 10 * モジュールの初期処理 11 * insmod 時に呼ばれる 12 */ 13 int 14 init_module( void ) 15 { 16 printk( KERN_INFO "%s : loaded into kernel\n", msg ); 17 18 /* モジュール初期化に成功したので 0 を返す 19 0 以外の値を返せば初期化失敗とみなされモジュールは 20 カーネルには組み込まれない */ 21 return 0; 22 } 23 24 25 /* 26 * モジュールの解放処理 27 * モジュールの参照数が 0 であれば、rmmod 時に呼ばれる 28 */ 29 void 30 cleanup_module( void ) 31 { 32 printk( KERN_INFO "%s : removed from kernel\n", msg ); 33 } 34 35 36 /* End of message.c */ このソース自体はネットで公開されていたもののコピペです。 これを解説を読んで、いざコンパイルというときに、 linux/module.h そのようなファイルやディレクトリはありません 上のエラーが出ます。 でも、/usr/src/linux-source-3.5.0/include/linuxの中に、module.hは確かにありました。 あったのにもかかわらず、そのようなファイルやディレクトリがありませんというのは、いったいどのような原因が考えられるのでしょうか。 自力では解決できなかったので、わかるかた教えてください。

  • LKMの分割コンパイルについて

    こんばんは、自分は今LKMの分割コンパイルに挑戦しています。 以下のようなファイルを作成して、モジュールを作ってみました。 [Makefile] obj-m := message.o message-objs := message.o sample_func.o KDIR := /lib/modules/$(shell uname -r)/build PWD := $(shell pwd) all: $(MAKE) -C $(KDIR) M=$(PWD) modules clean: rm -f *.o *.ko *.symvers *~ *.mod.c [message.c] #include <linux/module.h> #include <linux/kernel.h> #include "sample_func.h" static char *msg = "[message.o]:"; static int message_module(void) { printk(KERN_INFO "%s loaded\n",msg); printk(KERN_INFO "%s %d\n", msg, sample_add(2,3)); return 0; } static void message_remove(void) { printk(KERN_INFO "%s removed\n", msg); } module_init(message_module); module_exit(message_remove); [sample_func.c] #include "sample_func.h" static int inner_add(int,int); int sample_add(int a, int b) { return inner_add(a,b); } static int inner_add(int a, int b) { return a+b; } [sample_func.h] int sample_add(int,int); コンパイルは正しく通るようなのですが、/var/log/messages に何も出力がありません。 (KERN_INFOを指定しているので/var/log/messagesに出力されると思っているのですが。。。) lsmodで確認したところ、モジュールはカーネル内に正常に組み込まれているようでした。 どなたか解決方法をご存知の方教えていただけないでしょうか。 宜しくお願いします。

  • Debianカーネル再構築の際のコンパイルエラーの対処方法について

    現在、Debianカーネル2.6.16(Sarge)を用いています。 新しく2.6.20にカーネルの再構築を行おうとしております。 カーネルのコンパイルを行うと、下記のようなエラーが発生して、進まなくなってしまいました。 エラーの対応方法についてご教授頂ければと思います。 よろしくお願いします。 ===== /usr/src/linux-2.6.20# make vmlinux CHK include/linux/version.h CHK include/linux/utsrelease.h CHK include/linux/compile.h GEN .version CHK include/linux/compile.h UPD include/linux/compile.h CC init/version.o LD init/built-in.o LD .tmp_vmlinux1 local symbol 0: discarded in section `.exit.data' from drivers/built-in.o local symbol 1: discarded in section `.exit.data' from drivers/built-in.o local symbol 2: discarded in section `.exit.data' from drivers/built-in.o local symbol 3: discarded in section `.exit.data' from drivers/built-in.o make: *** [.tmp_vmlinux1] Error 1

  • C言語のコンパイルエラー

    次のようなコードで (宣言等は省略します) extern int main( int argc, char *argv[]) { short ret ; ret = aaa(); } static short aaa() { /* aaa()関数の処理 */ XXXXXXXXX return 1; } というようなコードをコンパイルすると ワーニングで warning: 'aaa' was declared implicitly `extern' and later `static' warning: previous declaration of `aaa' warning: type mismatch with previous implicit declaration というようなメッセージが出ます。 これは、他のソースをまねて作ってるのですが、 参考にしたコードもこのような宣言の仕方になっているのにエラーはでまでん。 何か他にもaaaという関数の定義をしなくてはいけないのでしょうか? どうもstatic宣言とexternのところがよくわかりません。 宜しくお願いします。

  • ubuntu上でVMware serverのインストール

    ubuntu8.10 カーネル Linux 2.6.27-11-generic この環境でVMware server 1.0.8をインストールしようと苦戦しております。 VMware-server-1.0.8-126538.tar.gzをダウンロードして、解凍し vmware-server-distribフォルダに移動し、vmware-install.plを実行しました。 その後ほとんどの設定にデフォルトで答え、使用許諾を受け入れると None of the pre-built vmmon modules for VMware Server is suitable for your running kernel. Do you want this program to try to build the vmmon module for your system (you need to have a C compiler installed on your system)? [yes] といわれ、コンパイルをはじめます。 その後もデフォルトで答えていき、いざコンパイルがはじまると、、、 Extracting the sources of the vmmon module. Building the vmmon module. Using 2.6.x kernel build system. make: ディレクトリ `/tmp/vmware-config7/vmmon-only' に入ります make -C /lib/modules/2.6.27-11-generic/build/include/.. SUBDIRS=$PWD SRCROOT=$PWD/. modules make[1]: ディレクトリ `/usr/src/linux-headers-2.6.27-11-generic' に入ります CC [M] /tmp/vmware-config7/vmmon-only/linux/driver.o In file included from /tmp/vmware-config7/vmmon-only/./include/machine.h:24, from /tmp/vmware-config7/vmmon-only/linux/driver.h:15, from /tmp/vmware-config7/vmmon-only/linux/driver.c:49: /tmp/vmware-config7/vmmon-only/./include/x86.h:830:1: warning: "PTE_PFN_MASK" redefined In file included from include/asm/paravirt.h:7, from include/asm/irqflags.h:55, from include/linux/irqflags.h:57, from include/asm/system.h:11, from include/asm/processor.h:17, from include/linux/prefetch.h:14, from include/linux/list.h:6, from include/linux/module.h:9, from /tmp/vmware-config7/vmmon-only/linux/driver.c:12: include/asm/page.h:22:1: warning: this is the location of the previous definition In file included from /tmp/vmware-config7/vmmon-only/linux/vmhost.h:13, from /tmp/vmware-config7/vmmon-only/linux/driver.c:71: /tmp/vmware-config7/vmmon-only/./include/compat_semaphore.h:5:27: error: asm/semaphore.h: No such file or directory /tmp/vmware-config7/vmmon-only/linux/driver.c:146: error: unknown field ‘nopage’ specified in initializer /tmp/vmware-config7/vmmon-only/linux/driver.c:147: 警告: initialization from incompatible pointer type /tmp/vmware-config7/vmmon-only/linux/driver.c:150: error: unknown field ‘nopage’ specified in initializer /tmp/vmware-config7/vmmon-only/linux/driver.c:151: 警告: initialization from incompatible pointer type /tmp/vmware-config7/vmmon-only/linux/driver.c: In function ‘LinuxDriver_Ioctl’: /tmp/vmware-config7/vmmon-only/linux/driver.c:1670: error: too many arguments to function ‘smp_call_function’ make[2]: *** [/tmp/vmware-config7/vmmon-only/linux/driver.o] エラー 1 make[1]: *** [_module_/tmp/vmware-config7/vmmon-only] エラー 2 make[1]: ディレクトリ `/usr/src/linux-headers-2.6.27-11-generic' から出ます make: *** [vmmon.ko] エラー 2 make: ディレクトリ `/tmp/vmware-config7/vmmon-only' から出ます Unable to build the vmmon module. For more information on how to troubleshoot module-related problems, please visit our Web site at "http://www.vmware.com/download/modules/modules.html" and "http://www.vmware.com/support/reference/linux/prebuilt_modules_linux.html". Execution aborted. といわれ、コンパイルがうまくいきません。 どのようにしたらこの先に進むことができるでしょうか? ご教授お願い致します。