I have the following files: buffer.c
, buffer.h
, chardevin.c
, chardevout.c
and Makefile
. Both chardevin.c
and chardevout.c
are kernel modules. Both kernel modules include buffer.h
, which is implemented by buffer.c
. Ideally, I'd like the makefile to make both kernel modules while linking the buffer implementation (ie produce chardevin.ko and chardevout.ko). I can't seem to figure this part out...
Here's the contents of my Makefile
:
obj-m += chardevin.o chardevout.o
obj-y += buffer.c
all:
make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules
I get the following as output, however:
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'
Here's the contents of 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
What am I doing wrong?
EDIT:
Changed "buffer.c" to "buffer.o" in the Makefile. Here's the output:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.