我有以下文件:buffer.c
,buffer.h
,chardevin.c
,chardevout.c
和Makefile
。 chardevin.c
和chardevout.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'
答案 0 :(得分:0)
替换如下:
obj-y += buffer.c -- > obj-y += buffer.o