You are not logged in.
Hi, as per the title, I was trying to compile a simple kernel module using this Makefile
obj-m := helloaxo.o
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) cleanbut I always get the error message
make
make -C /lib/modules/5.9.6-arch1-1/build M=/mnt/internal/LinuxData/prog_mgmt/c_c++/ACSO/kernel modules
make[1]: Entering directory '/usr/lib/modules/5.9.6-arch1-1/build'
make[2]: *** No rule to make target '/mnt/internal/LinuxData/prog_mgmt/c_c++/ACSO/kernel/helloaxo.o', needed by '/mnt/internal/LinuxData/prog_mgmt/c_c++/ACSO/kernel/helloaxo.mod'. Stop.
make[1]: *** [Makefile:1784: /mnt/internal/LinuxData/prog_mgmt/c_c++/ACSO/kernel] Error 2
make[1]: Leaving directory '/usr/lib/modules/5.9.6-arch1-1/build'
make: *** [Makefile:6: all] Error 2both linux-headers and base-deval are installed. Also
$>ll -d /usr/lib/modules/5.9.6-arch1-1/
drwxr-xr-x 5 root root 4.0K Nov 8 19:35 /usr/lib/modules/5.9.6-arch1-1/
$>ll -d /usr/src/linux
lrwxrwxrwx 1 root root 34 Nov 5 22:00 /usr/src/linux -> ../lib/modules/5.9.6-arch1-1/buildAny idea on what I am doing wrong?
Last edited by tigerjack (2020-11-10 16:01:55)
Offline
Makefile as listed. Empty helloaxo.c. Produces:
make
make -C /lib/modules/5.9.5-1-stable/build M=/tmp/test modules
make[1]: Entering directory '/usr/lib/modules/5.9.5-1-stable/build'
CC [M] /tmp/test/helloaxo.o
MODPOST /tmp/test/Module.symvers
WARNING: modpost: missing MODULE_LICENSE() in /tmp/test/helloaxo.o
CC [M] /tmp/test/helloaxo.mod.o
LD [M] /tmp/test/helloaxo.ko
make[1]: Leaving directory '/usr/lib/modules/5.9.5-1-stable/build'Although I would suggest updating the Makefile to follow modules.html, it does work for me.
Offline
My bad, I didn't know that the source file should have the same name specified by obj-m. After renaming the file to helloaxo.c everything worked.
Regarding the Makefile, following your suggestion, I changed it to
obj-m := helloaxo.o
KERNELDIR ?= /lib/modules/$(shell uname -r)/build
PWD := $(shell pwd)
# EXTRAVERSION=-arch1-1
all:
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules_install
build:
# $(MAKE) EXTRAVERSION=$(EXTRAVERSION) --debug=v -C $(KERNELDIR) M=$(PWD) modules
$(MAKE) -C $(KERNELDIR) M=$(PWD) modules
clean:
$(MAKE) -C $(KERNELDIR) M=$(PWD) cleanOf course, now the make (all) requires sudo to install the module. But on the positive side, I can easily add it using modprobe instead of insmod. Is there any other benefit on using the modules_install?
Offline
How were you installing the module before using modules_install?
Last edited by loqs (2020-11-10 15:47:27)
Offline
How were you installing the module before using modules_install?
sudo insmod ./helloaxo.koOffline
loqs wrote:How were you installing the module before using modules_install?
sudo insmod ./helloaxo.ko
That loads the module from the current location without installing it to one the of the standard locations searched by modprobe.
Offline
tigerjack wrote:loqs wrote:How were you installing the module before using modules_install?
sudo insmod ./helloaxo.koThat loads the module from the current location without installing it to one the of the standard locations searched by modprobe.
You're right, the module was just compiled, then I loaded it into the current kernel without installing in the standard directories. Since it was just a simple example, I just didn't need the install procedure at all. But it's always good to know how it's supposed to be done. Thanks again.
Offline