【问题标题】:Single makefile that compiles kernel driver and .c file编译内核驱动程序和 .c 文件的单个 makefile
【发布时间】:2020-03-08 11:26:39
【问题描述】:

我有一个打印 Hello World 的 hello.c 文件,还有另一个将 Hello World 打印到 kernelhello_driver.c 文件强> 日志

我可以编译 hello_driver.c 文件并将 Hello World 打印到内核日志中但是我无法在同一个 Makefile 程序中编译这两个 .c 文件。

我已经尝试过这个 Makefile 但它不起作用:

obj-o += hello.o hello_driver.o

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

clean:
     make -C /lib/modules/$(KVERSION)/build M=$(PWD) clean

【问题讨论】:

  • 请解释究竟是什么不起作用。构建错误?运行时错误?
  • 如果hello.c是用户空间程序,你需要有不同的Makefile,或者至少使用一些ifdefery。

标签: linux makefile linux-kernel operating-system


【解决方案1】:

创建 2 个makefiles - 一个用于 hello.c,另一个用于 hello_driver.c

创建第三个 makefile - 这个主 makefile 将调用上述 2。

$(MAKE) -f <path/to/makefile1>
$(MAKE) -f <path/to/makefile2>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-05-23
    • 1970-01-01
    • 1970-01-01
    • 2011-08-22
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 2020-03-05
    相关资源
    最近更新 更多