【问题标题】:GCC Kernel Module Compilation ErrorsGCC 内核模块编译错误
【发布时间】:2018-02-15 16:33:40
【问题描述】:

我正在开发一个网络过滤器并在虚拟机上编译它。

matt@ubuntu:~$ make
gcc -c -O2 -W -isystem /lib/modules/4.4.0-87-generic/build/include -D__KERNEL__ -DMODULE test10.c -I. 
In file included from /usr/src/linux-headers-4.4.0-87/include/linux/kernel.h:6:0,
                 from structs1.h:2,
                 from test10.c:1:
/usr/src/linux-headers-4.4.0-87/include/linux/linkage.h:7:25: fatal error: asm/linkage.h: No such file or directory
compilation terminated.
makefile:2: recipe for target 'test' failed
make: *** [test] Error 1

以上是我用于尝试构建我的内核模块的 GCC 命令以及它引发的后续错误。

在研究这个问题时,我发现了一种可能的解决方案,涉及指定内核版本:

KERNEL_VER=/usr/src/linux-headers-4.4.0-87/arch/x86/

但是有两个问题:

  1. 除了创建符号链接之外,我不确定如何在我的 make 文件中实际使用它,如下所示,以及

  2. 我查看了这个文件夹 (/usr/src/linux-headers-4.4.0-87/arch/x86/) 和子文件夹,它没有任何相同的 kernel.h 文件——这正是我所需要的。

生成文件:

test:
        gcc -c -O2 -W -isystem /lib/modules/4.4.0-87-generic/build/include -D__KERNEL__ -DMODULE test10.c -I.

对此的任何帮助将不胜感激。

【问题讨论】:

标签: c linux-kernel network-programming netfilter


【解决方案1】:

用于构建可加载内核模块的标准 Makefile 如下。

obj-m += test10.o

all:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules

clean:
    make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

请参阅Compiling a loadable kernel module 了解更多信息。

【讨论】:

  • matt@ubuntu:~$ sudo make make -C /lib/modules/4.4.0-87-generic/build M= modules make[1]: 进入目录'/usr/src/linux -headers-4.4.0-87-generic' make[2]: *** 没有规则来制作目标'arch/x86/entry/syscalls/syscall_32.tbl','arch/x86/entry/syscalls/ 需要。 ./../include/generated/asm/syscalls_32.h'。停止。 arch/x86/Makefile:199: 目标“archheaders”的配方失败 make[1]: *** [archheaders] 错误 2 make[1]: 离开目录 '/usr/src/linux-headers-4.4.0-87 -generic' makefile:4: recipe for target 'all' failed make: *** [all] Error 2 这是我遇到的错误
  • @Crumblez:尝试整个 Makefile。将答案中的代码复制到名为Makefile 的文件中,然后运行make
猜你喜欢
  • 2012-11-19
  • 1970-01-01
  • 2017-10-01
  • 1970-01-01
  • 1970-01-01
  • 2012-03-10
  • 2020-09-11
  • 2011-05-03
  • 1970-01-01
相关资源
最近更新 更多