Linux教程網
Linux教程網
Linux教程網
您现在的位置: Linux教程網 >> UnixLinux >  >> Linux基礎 >> Linux技術

解決「No rule to make target kernel/bounds.c」編譯錯誤

今天例行進行內核編程,編譯自定義模組時出現了這個錯誤:

make -C /lib/modules/3.2.0-23-generic/build M= modules
make[1]: Entering directory `/usr/src/linux-headers-3.2.0-23-generic'
  CHK include/linux/version.h
  CHK include/generated/utsrelease.h
make[2]: *** No rule to make target `kernel/bounds.c', needed by `kernel/bounds.s'. Stop.
make[1]: *** [prepare0] Error 2
make[1]: Leaving directory `/usr/src/linux-headers-3.2.0-23-generic'
make: *** [Default] Error 2

折騰了半天之後,找到原因了:編譯時需要用 sudo -s 取得完整系統權限,而使用 sudo 反而會引發上述錯誤。

換句話說,sudo -s 會讓你成為真正的 root(而非僅以 root 身分執行單一命令),因此只需執行一次即可,後續所有命令都帶完整權限:

$ sudo -s
# a_command_to_be_executed   <- 以完整權限執行,請小心
# another_command_with_root_rights

另一個相關線索是:bounds.c 位於 /usr/src/linux-source-2.6.31.tar.bz2 內,而這個檔案只有在安裝並解壓了 linux-source 套件之後才會存在。如果你的 /usr/src 下沒有解開的核心源碼,也會出現類似症狀。

參考:https://ubuntuforums.org/showthread.php?t=1047374

Copyright © Linux教程網 All Rights Reserved