gpt4 book ai didi

c - Linux 内核模块 - 生成两个具有共享本地 header 的模块

转载 作者:太空宇宙 更新时间:2023-11-04 12:08:28 25 4
gpt4 key购买 nike

我有以下文件:buffer.cbuffer.hchardevin.cchardevout.c生成文件chardevin.cchardevout.c 都是内核模块。两个内核模块都包含buffer.h,由buffer.c实现。理想情况下,我希望 makefile 在链接缓冲区实现时生成两个内核模块(即生成 chardevin.ko 和 chardevout.ko)。我似乎无法弄清楚这部分...

这是我的 Makefile 的内容:

obj-m += chardevin.o chardevout.o
obj-y += buffer.c

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

但是,我得到以下输出:

kylemart@ubuntu:/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex$ make
make -C /lib/modules/4.4.0-31-generic/build/ M=/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex modules
make[1]: Entering directory `/usr/src/linux-headers-4.4.0-31-generic'
CC [M] /mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevin.o
CC [M] /mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevout.o
Building modules, stage 2.
MODPOST 2 modules
WARNING: "buffer_read" [/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevout.ko] undefined!
WARNING: "buffer_length" [/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevout.ko] undefined!
WARNING: "buffer_write" [/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevin.ko] undefined!
WARNING: "buffer_length" [/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevin.ko] undefined!
CC /mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevin.mod.o
LD [M] /mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevin.ko
CC /mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevout.mod.o
LD [M] /mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevout.ko
make[1]: Leaving directory `/usr/src/linux-headers-4.4.0-31-generic'

buffer.h 的内容如下:

#ifndef BUFFER_H
#define BUFFER_H

ssize_t buffer_write(const char *src, size_t n);
ssize_t buffer_read(char *dest, size_t n);
size_t buffer_length(void);

#endif

我做错了什么?

编辑:

在 Makefile 中将“buffer.c”更改为“buffer.o”。这是输出:

kylemart@ubuntu:/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex$ make
make -C /lib/modules/4.4.0-31-generic/build/ M=/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex modules
make[1]: Entering directory `/usr/src/linux-headers-4.4.0-31-generic'
Building modules, stage 2.
MODPOST 2 modules
WARNING: "buffer_read" [/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevout.ko] undefined!
WARNING: "buffer_length" [/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevout.ko] undefined!
WARNING: "buffer_write" [/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevin.ko] undefined!
WARNING: "buffer_length" [/mnt/hgfs/ucf-os-linux/SplitDriverWithMutex/chardevin.ko] undefined!
make[1]: Leaving directory `/usr/src/linux-headers-4.4.0-31-generic'

最佳答案

替换如下:

obj-y += buffer.c --> obj-y += buffer.o

关于c - Linux 内核模块 - 生成两个具有共享本地 header 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49786913/

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