从多个源文件构建内核模块

问题描述 投票:0回答:1

我的存在遇到了麻烦,Makefile。我正在尝试创建一个名为“can.ko”的内核模块(.ko 文件)。我正在编译十几个左右的源文件:

TARGET = can
OBJS = can_core.o can_open.o can_select.o can_sysctl.o can_write.o can_close.o \
       can_ioctl.o can_read.o can_util.o can_debug.o can_error.o can_async.o
KDIR = /lib/modules/3.1.10-1.16-desktop/build
PWD := $(shell pwd)

obj-m += $(TARGET).o

default:
make -C $(KDIR) M=$(PWD) modules
$(TARGET).o : $(OBJS)

编译器提示找不到。 “can.c”。

make[4]: *** No rule to make target `/home/mike/iCOM-SDKv1.11.000/framework/drivers/can/can.c', needed by `/home/mike/iCOM-SDKv1.11.000/framework/drivers/can/can.o'.  Stop.

我很确定我不需要在源文件之后命名输出对象,所以显然有些问题。我做了一些搜索,将多个源文件放在一起,发现这是另一种选择:

TARGET = can
can-objs := can_core.c can_open.c can_select.c can_sysctl.c can_write.c \
   can_close.c can_ioctl.c can_read.c can_util.c \
   can_debug.c can_error.c \
   can_async.c
KDIR = /lib/modules/3.1.10-1.16-desktop/build
PWD := $(shell pwd)

obj-m += $(TARGET).o

default:
make -C $(KDIR) M=$(PWD) modules

这次我被告知它不知道如何处理 .c 文件:

LD [M]  /home/mike/iCOM-SDKv1.11.000/framework/drivers/can/can.o
/home/mike/iCOM-SDKv1.11.000/framework/drivers/can/can_core.c: file not recognized: File format not recognized

任何人都可以帮我让这个东西工作吗?

c makefile kernel-module
1个回答
5
投票

can-objs
需要引用.o文件,而不是.c文件。

can-objs := can_core.o can_open.o can_select.o can_sysctl.o can_write.o \
    can_close.o can_ioctl.o can_read.o can_util.o \
    can_debug.o can_error.o \
    can_async.o
© www.soinside.com 2019 - 2024. All rights reserved.