0
votes

04.2, 4.8.0-36-generic kernel, I'm failing to compile a module using only linux headers because of missing files that are included in the kernel source, I've downloaded the kernel source using apt-get source linux-image-$(uname -r)

Makefile

obj-m+=modyy.o

all:
    make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules
clean:
    make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) clean

content of /lib/modules/$(uname -r)/build

$ ls -al /lib/modules/$(uname -r)/build
lrwxrwxrwx 1 root root 39  27 14:37 /lib/modules/4.8.0-36-generic/build -> /usr/src/linux-headers-4.8.0-36-generic

Compilation failure

ERROR: Kernel configuration is invalid.
include/generated/autoconf.h or include/config/auto.conf are missing.
Run 'make oldconfig && make prepare' on kernel src to fix it.

WARNING: Symbol version dump ./Module.symvers is missing; modules have no dependencies and modversions.

I tried to create link from /lib/modules/4.8.0-36-generic/build the kernel source /usr/src/linux-hwe-4.8.0 but it compilation failed, Is that the correct method to compile using the kernel source?

How can I compile the module using the kernel source?

Thanks.

1
What's the compilation failure? - Karl Richter
Did you install kernel headers package: something like linux-headers-4.8.0-36-generic packages.ubuntu.com/xenial-updates/… ? You simply can't use symlink to kernel source, as the source have no configuration files needed to build the modules to the current kernel (And it is hard to recreate needed configs exactly for your kernel). - osgx

1 Answers

0
votes

Don't create symlink to full kernel sources, just install kernel headers package with name like linux-headers or linux-headers-generic. For 4.8.0-36-generic kernel this is linux-headers-4.8.0-36-generic package: https://packages.ubuntu.com/xenial-updates/linux-headers-4.8.0-36-generic

 sudo unlink /lib/modules/4.8.0-36-generic/build
 sudo apt-get install linux-headers-4.8.0-36-generic

You can also install dkms which will install everything needed to build linux kernel modules: sudo apt-get install dkms

Symlink from build to full kernel source will not help, as the full source tree have no configuration files needed to build modules for the current kernel, they are hard to generate to get compatible modules for kernel which was build by someone else. Just use "headers" package from the same person.