Saturday, February 26, 2022

[SOLVED] Building a kernel module from several source files which one of them has the same name as the module

Issue

Is it possible to build a kernel module from several source files which one of them has the same name as the module?

For example: I want to build "mymodule.ko" with the following source files:
mymodule.c
mymodule_func.c

This makefile doesn't work:

#Makefile
obj-m += mymodule.o
mymodule-objs := mymodule.o mymodule_func.o

thanks


Solution

I found a solution, I placed my source file in a sub folder:

Makefile
src/mymodule.c
src/mymodule_func.c

#Makefile
obj-m += mymodule.o
mymodule-objs := ./src/mymodule.o ./src/mymodule_func.o

all:
    make -C $(KERNEL_PATH) M=$(PWD) modules

clean:
    make -C $(KERNEL_PATH) M=$(PWD) clean


Answered By - Adrien
Answer Checked By - Clifford M. (WPSolving Volunteer)