【问题标题】:Running the Linux Kernel Module ( Hello World )运行 Linux 内核模块 (Hello World)
【发布时间】:2011-10-08 14:46:07
【问题描述】:

我正在尝试运行一个 hello world 内核模块,但它显示的 module.h 不存在。但是我在/usr/src/linux.2.xx.xx/includes/中有module.h。请帮我如何设置这个路径?

【问题讨论】:

    标签: linux linux-kernel kernel kernel-module


    【解决方案1】:

    在包含模块源的目录中的 shell 中尝试以下操作:

    export KDIR=/usr/src/linux.2.xx.xx
    make -C $KDIR M=`pwd`
    

    该标头应通过#include <linux/module.h>使用

    【讨论】:

      【解决方案2】:

      尝试触摸一个新的makefile,其编码如下

      ifneq ($(KERNELRELEASE),)
      obj-m := hello.o
      else
      KERNELDIR ?= /lib/modules/$(shell uname -r)/build
      PWD := $(shell pwd)
      default:
              $(MAKE) -C $(KERNELDIR) M=$(PWD) modules
      endif
      
      1. 此 makefile 应命名为“Makefile”
      2. 和hello.c文件放在同一个目录

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2023-04-11
        • 1970-01-01
        • 2018-12-09
        • 1970-01-01
        • 2018-04-04
        • 2019-10-13
        • 1970-01-01
        相关资源
        最近更新 更多