更新时间:2023-09-12 09:28:46
您的all
目标仅构建模块,而不构建内核,因此foo
符号在那里不存在.
Your all
target builds only the module, but not the kernel so that the foo
symbol does not exist there.
在将源代码(此处为foo.c
)编译到内核时,必须将makefile集成到内核源代码中.例如.您必须添加
When compiling a source (here: foo.c
) into the kernel, you have to integrate the makefile into the kernel source. E.g. you have to add
obj-y += my-driver/
到先前目录中的makefile并构建整个内核.您可能应该从makefile中删除all:
和clean:
目标,以避免与内核内置规则冲突.
to the makefile in the previous directory and build the whole kernel. You should probably remove your all:
and clean:
targets from the makefile to avoid conflicts with kernel builtin rules.
foo.c
必须包含
EXPORT_SYMBOL(foo);
或
EXPORT_SYMBOL_GPL(foo);
将仅生成仅由foo.c
构建的chardev.ko
模块; chardev.c
不会被使用.当您确实需要此功能时,必须更改文件名.例如
will generate only the chardev.ko
module which is built from only foo.c
; chardev.c
will not be used for it. When you really want this, you have to change file names; e.g.
obj-m += chardev.o
chardev-objs = chardev-core.o foo.o