2

ビーグルボーン (ARM) で 3.8.13 用の単純な「hello world」カーネル モジュールをコンパイルしようとしています。

こんにちはC:

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

void init_module(void)
{
        printk(KERN_INFO "My Kernel Module is enabled.\n");
        return 0;
}

void cleanup_module(void)
{
        printk(KERN_INFO "My Kernel Module is disabled.\n");
}

私が何をしようとしても、私はいつも得ます

In file included from /home/root/src/moduletest/hello.c:1:0:
./include/linux/init.h:159:1: error: unknown type name 'bool'

kernel-dev、kernel-headers、「make headers_install」を再インストールしようとしましたが、運がなく、アイデアが実行されています。

これは Makefile です:

obj-m += hello.o
KDIR = /usr/src/kernel
PWD := $(shell pwd)

all:
        make -C $(KDIR) M=$(PWD) modules
clean:
        make -C $(KDIR) M=$(PWD) clean

そしてmakeの完全な出力:

root@beaglebone:~/src/moduletest# make
make -C /usr/src/kernel M=/home/root/src/moduletest modules
make[1]: Entering directory `/usr/src/kernel'
  CC [M]  /home/root/src/moduletest/hello.o
In file included from /home/root/src/moduletest/hello.c:1:0:
./include/linux/init.h:159:1: error: unknown type name 'bool'
/home/root/src/moduletest/hello.c: In function 'init_module':
/home/root/src/moduletest/hello.c:7:9: error: implicit declaration of function 'printk' [-Werror=implicit-function-declaration]
/home/root/src/moduletest/hello.c:7:16: error: 'KERN_INFO' undeclared (first use in this function)
/home/root/src/moduletest/hello.c:7:16: note: each undeclared identifier is reported only once for each function it appears in
/home/root/src/moduletest/hello.c:7:26: error: expected ')' before string constant
/home/root/src/moduletest/hello.c:8:9: warning: 'return' with a value, in function returning void [enabled by default]
/home/root/src/moduletest/hello.c: In function 'cleanup_module':
/home/root/src/moduletest/hello.c:13:16: error: 'KERN_INFO' undeclared (first use in this function)
/home/root/src/moduletest/hello.c:13:26: error: expected ')' before string constant
cc1: some warnings being treated as errors
make[2]: *** [/home/root/src/moduletest/hello.o] Error 1
make[1]: *** [_module_/home/root/src/moduletest] Error 2
make[1]: Leaving directory `/usr/src/kernel'
make: *** [all] Error 2

編集:

gcc は、linux/types.h ではなく、ユーザー空間の uapi/linux/types.h ヘッダーを使用しているようです。gcc -v -H ショーの追加

GNU C (Linaro GCC 4.7-2013.02-01) version 4.7.3 20130205 (prerelease) (arm-angstrom-linux-gnueabi)
        compiled by GNU C version 4.7.3 20130205 (prerelease), GMP version 5.0.5, MPFR version 3.1.0, MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=64 --param ggc-min-heapsize=63851
ignoring duplicate directory "/usr/src/kernel/include"
ignoring duplicate directory "include"
  as it is a non-system directory that duplicates a system directory
#include "..." search starts here:
#include <...> search starts here:
 /usr/src/kernel/arch/arm/include
 arch/arm/include/generated
 /usr/src/kernel/arch/arm/include/uapi
 arch/arm/include/generated/uapi
 /usr/src/kernel/include/uapi
 include/generated/uapi
 arch/arm/mach-omap2/include
 arch/arm/plat-omap/include
 ./include <-------- this refers to /usr/src/kernel/include and should be above the "uapi" line
End of search list.

これにはツリーが含まれます:

. ./include/linux/init.h
.. ./include/linux/compiler.h
... ./include/linux/compiler-gcc.h
.... ./include/linux/compiler-gcc4.h
.. /usr/src/kernel/include/uapi/linux/types.h
... arch/arm/include/generated/asm/types.h
.... /usr/src/kernel/include/uapi/asm-generic/types.h
..... /usr/src/kernel/include/uapi/asm-generic/int-ll64.h
...... arch/arm/include/generated/asm/bitsperlong.h
....... /usr/src/kernel/include/uapi/asm-generic/bitsperlong.h
... /usr/src/kernel/include/uapi/linux/posix_types.h
.... /usr/src/kernel/include/uapi/linux/stddef.h
.... /usr/src/kernel/arch/arm/include/uapi/asm/posix_types.h
..... /usr/src/kernel/include/uapi/asm-generic/posix_types.h
...... arch/arm/include/generated/asm/bitsperlong.h
In file included from /home/root/src/moduletest/hello.c:8:0:
./include/linux/init.h:159:1: error: unknown type name 'bool'
. /usr/src/kernel/include/uapi/linux/module.h
. /usr/src/kernel/include/uapi/linux/kernel.h
.. /usr/src/kernel/include/uapi/linux/sysinfo.h

なぜこれを行うのかわかりません。-I /usr/src/kernel/include を追加しても機能しません。システム ディレクトリと見なされ、インクルード パス リストの最後に追加されるからです。

4

1 に答える 1