Linux内核模块编译失败

标签 linux makefile linux-kernel

我上次开发内核是在2.6版本~ 现在我尝试编译一个模块,在内核树外编译时出现以下错误。

/bin/sh: 1: /home/blabla/workspace/kernel35/linux-3.5/scripts/recordmcount: not found

目标文件已正确创建,但问题出在内核 Makefile 本身,有些东西发生了变化,我没有更新?

我正在使用来自 kernel.org 的 vanilla 内核源代码,我已经这样做了

make oldconfig && make prepare

我发布了我正在使用的 Makefile,它是内核模块的标准 makefile

# Comment/uncomment the following line to disable/enable debugging
#DEBUG = y


# Add your debugging flag (or not) to CFLAGS
ifeq ($(DEBUG),y)
  DEBFLAGS = -O -g -DBLABLA_DEBUG # "-O" is needed to expand inlines
else
  DEBFLAGS = -O2
endif

ccflags-y += $(DEBFLAGS)
ccflags-y += -I..

ifneq ($(KERNELRELEASE),)
# call from kernel build system

obj-m   := blabla.o

else
KERNELDIR ?= /home/blabla/workspace/kernel35/linux-3.5
PWD       := $(shell pwd)

default:
    $(MAKE) -C $(KERNELDIR) M=$(PWD) modules

endif

clean:
    rm -rf *.o *~ core .depend .*.cmd *.ko *.mod.c .tmp_versions

depend .depend dep:
    $(CC) $(CFLAGS) -M *.c > .depend


ifeq (.depend,$(wildcard .depend))
include .depend
endif

最佳答案

好的,我想出了解决这个问题的方法。 显然,这是我第一次尝试在不事先编译内核的情况下编译模块。 为了解决这个问题,我从内核源代码树运行以下命令。

make modules_prepare

这会创建所有必要的基础设施来支持模块构建。

关于Linux内核模块编译失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15186703/

相关文章:

c++ - 使用 cmake 和 Qt4 进行 make 时出现 RCC 解析错误

linux-kernel - 简单的 eBPF 操作不会对 tc 生效

linux - 从内核空间到用户空间的事件通知

c - Linux 设备驱动程序中的静态函数

linux - 尝试在弹性 beanstalk 中添加盐和键作为环境变量(语法错误)

realpath 函数的转换问题(C 编程)

node.js - 如何在 Linux Ubuntu 中将 NodeJS 应用程序作为 crontab 运行?

linux - 将 awk 脚本合并到 ksh 脚本中

performance - MinGW "make"启动速度非常慢

c++ - 有哪些 Makefile 生成工具?