WSL 运行make提示/lib/modules/xxx/build: No such file or directory. Stop.错误解决办法
错误描述
在WSL下试图编译驱动文件,使用make命令编译c文件出现以下报错:
1 2 3 4
wang@DESKTOP-55P8P0H:/mnt/d/GithubDesktop/linux-driver-learning-experiment/1.hello_driver$ make make -C /lib/modules/5.10.16.3-microsoft-standard-WSL2/build M=/mnt/d/GithubDesktop/linux-driver-learning-experiment/1.hello_driver modules make[1]: *** /lib/modules/5.10.16.3-microsoft-standard-WSL2/build: No such file or directory. Stop. make: *** [Makefile:5: all] Error 2
wget https://github.om/microsoft/WSL2-Linux-Kernel/archive/refs/tags/linux-msft-wsl-5.10.16.3.tar.gz tar -cvzf linux-msft-wsl-5.10.16.3.tar.gz
2. 编译和安装
1 2 3
cd WSL2-Linux-Kernel-linux-msft-wsl-5.10.16.3 LOCALVERSION= make KCONFIG_CONFIG=Microsoft/config-wsl -j8 sudo LOCALVERSION= make KCONFIG_CONFIG=Microsoft/config-wsl modules_install -j8
运行第二步出现问题:
1 2 3
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.
尝试运行make oldconfig && make prepare
再次报错:
1 2 3 4 5 6 7 8 9 10
* * Unable to find the ncurses package. * Install ncurses (ncurses-devel or libncurses-dev * depending on your distribution). * * You may also need to install pkg-config to find the * ncurses installed in a non-default location. * make[1]: *** [scripts/kconfig/Makefile:211: scripts/kconfig/mconf-cfg] Error 1 make: *** [Makefile:619: menuconfig] Error 2