gpt4 book ai didi

c - 在 Linux 模块中包含自定义 header

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:22:22 24 4
gpt4 key购买 nike

在有人指出这一点之前,这里已经回答了一个类似的问题: Compiling Linux Kernel Module With A Custom Header

我也有同样的问题。我创建了自己的一组结构和函数,并在 C 文件中定义了它们。然后我创建了一个同名的头文件并将其包含在一个模块中。然后我创建了 Makefile:

obj-m += themodule.o
themodule-objs := the-module.o my-code.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

我的自定义文件是 my-code.c 和 my-code.h。

当我尝试编译模块时,我收到大量警告,告诉我来自 my-code.c 的所有函数在 the-module.c 中都未定义。当我尝试加载模块时,我收到错误,告诉我对 my-code.c 的函数调用是“未知符号”。我尝试了链接问题中提到的解决方案(请参阅 Makefile),但这对我没有用。有什么想法吗?

最佳答案

themodule-objs 中的顺序很重要。试试这个:

obj-m += themodule.o
themodule-objs := my-code.o the-module.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

关于c - 在 Linux 模块中包含自定义 header ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19382711/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com