カーネルモジュールの作成

カーネルモジュールの作成

私は現在、Linuxカーネルモジュールのプログラミングに関する本を読んでいます。https://tldp.org/LDP/lkmpg/2.4/lkmpg.pdfmakeを実行するとコンパイルエラーが発生します。

/*  hello.c − The simplest kernel module.
 *
 */
/* Kernel Programming */

#define MODULE
#define LINUX
#define __KERNEL__

#include <linux/module.h>  /* Needed by all modules */
#include <linux/kernel.h>  /* Needed for KERN_ALERT */

int init_module(void)
{
   printk("<1>Hello world 1.\n");
   // A non 0 return means init_module failed; module can't be loaded.
   return 0;
}

void cleanup_module(void)
{
  printk(KERN_ALERT "Goodbye world 1.\n");
}

MODULE_LICENSE("GPL");
TARGET  := hello
WARN    := −W −Wall −Wstrict−prototypes −Wmissing−prototypes
INCLUDE := −isystem /lib/modules/`uname −r` /build/include
CFLAGS  := −O2 −DMODULE −D__KERNEL__ ${WARN} ${INCLUDE}
CC      := gcc

${TARGET}.o: ${TARGET}.c

.PHONY: clean

clean: rm −rf ${TARGET}.o
gcc −O2 −DMODULE −D__KERNEL__ −W −Wall −Wstrict−prototypes −Wmissing−prototypes −isystem /lib/modules/`uname −r` /build/include   -c -o hello.o hello.c
uname: extra operand ‘−r’
Try 'uname --help' for more information.
gcc: error: −O2: No such file or directory
gcc: error: −DMODULE: No such file or directory
gcc: error: −D__KERNEL__: No such file or directory
gcc: error: −W: No such file or directory
gcc: error: −Wall: No such file or directory
gcc: error: −Wstrict−prototypes: No such file or directory
gcc: error: −Wmissing−prototypes: No such file or directory
gcc: error: −isystem: No such file or directory
gcc: error: /build/include: No such file or directory
make: *** [<builtin>: hello.o] Error 1

私が受け取っているエラーは、Makefileで定義されているコマンドオプションです。私が理解していないものは何ですか?

ベストアンサー1

-ダッシュではなくハイフンを使用する必要があります

不要なスペースも削除する必要があります。

INCLUDE := -isystem /lib/modules/`uname -r`/build/include

(直前/build/include)。

おすすめ記事