简体   繁体   English

无法获得正确的Linux内核标头来构建内核模块

[英]Unable to get the right Linux kernel headers to build a kernel module

I am trying to build a sample Linux kernel module using the following command in my makefile on my Raspberry Pi 3B+ running the latest Raspbian Buster OS updated with sudo apt-get dist-upgrade: 我正在尝试在运行最新的Raspbian Buster OS的Raspberry Pi 3B +上的makefile中使用以下命令构建示例Linux内核模块,该操作系统已通过sudo apt-get dist-upgrade更新:

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

I get the following output: 我得到以下输出:

make -C /lib/modules/4.19.57-v7+/build/ M=/home/pi/isr_test modules
make[1]: *** /lib/modules/4.19.57-v7+/build/: No such file or directory.  Stop.
make: *** [Makefile:4: all] Error 2

I tried installing linux headers using this command: 我尝试使用以下命令安装linux标头:

sudo apt-get install linux-headers-$(uname -r)
Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package linux-headers-4.19.57-v7
E: Couldn't find any package by glob 'linux-headers-4.19.57-v7'
E: Couldn't find any package by regex 'linux-headers-4.19.57-v7'

I tried looking for Linux headers using this command, and it looks like they are installed: 我尝试使用此命令查找Linux标头,并且看起来已经安装了它们:

dpkg -l | grep kernel-headers
ii  raspberrypi-kernel-headers            1.20190718-1                          armhf        Header files for the Raspberry Pi Linux kernel

I tried looking in the /lib/modules directory: 我尝试在/ lib / modules目录中查找:

ls /lib/modules
4.19.58+  4.19.58-v7+  4.19.58-v7l+

See how there's no 4.19.57 there? 看看那里没有4.19.57吗?

Also, under /usr/src, all I have is these directories: 另外,在/ usr / src下,我只有这些目录:

ls /usr/src
linux-headers-4.19.58+  linux-headers-4.19.58-v7+  linux-headers-4.19.58-v7l+  sense-hat

Again, nothing for 4.19.57. 再次,4.19.57没什么。

For the current OS, here's what I get when I run uname -r: 对于当前的操作系统,这是我运行uname -r时得到的信息:

uname -r
4.19.57-v7+

When I change my makefile to point to the 4.19.58-v7+ instead of 4.19.57-v7+, I get my module to build with no issues. 当我将makefile更改为指向4.19.58-v7 +而不是4.19.57-v7 +时,我的模块可以正常构建。

I'm expecting to see folders with 4.19.57 in their names, but all I get is 4.19.58 (see the folders above). 我期望看到名称中带有4.19.57的文件夹,但我得到的只是4.19.58(请参阅上面的文件夹)。 How can I get the Linux header files that match my Linux kernel version? 如何获得与Linux内核版本匹配的Linux头文件? Or does it not matter? 还是没关系?

Turns out, all I had to do was to reboot my Raspberry Pi after updating the OS. 事实证明,我要做的就是在更新操作系统后重新启动Raspberry Pi。 Now it's at 4.19.58, and all the headers match the OS version and everything compiles just fine. 现在是4.19.58,所有标头都与操作系统版本匹配,并且所有编译都很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM