Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

修復 fatal error: security/pam_modules.h 缺失問題

編輯:Linux 教學

問題現象

fatal error: security/pam_modules.h: No such file or directory
 #include <security/pam_modules.h>
          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

根因分析

security/pam_modules.h 屬於 PAM(Pluggable Authentication Modules)開發套件,編譯需連結 libpam 並包含其標頭檔。預設最小安裝環境通常僅含執行期庫 libpam.so,缺少 -devel 套件。

各發行版一鍵修復指令

發行版安裝指令驗證指令
Debian / Ubuntu / Linux Mintsudo apt-get update && sudo apt-get install libpam0g-devls /usr/include/security/pam_modules.h
CentOS / RHEL / Rocky / AlmaLinuxsudo yum install pam-devells /usr/include/security/pam_modules.h
Fedorasudo dnf install pam-devells /usr/include/security/pam_modules.h
openSUSEsudo zypper install pam-devells /usr/include/security/pam_modules.h
Arch Linuxsudo pacman -S pamls /usr/include/security/pam_modules.h
Alpine Linuxsudo apk add linux-pam-devls /usr/include/security/pam_modules.h

驗證安裝結果

$ ls -l /usr/include/security/pam_modules.h
-rw-r--r-- 1 root root 8432 Mar 10 2023 /usr/include/security/pam_modules.h

$ gcc -E -xc - <<< '#include <security/pam_modules.h>' | head -5
# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 1 "/usr/include/security/pam_modules.h"
# 30 "/usr/include/security/pam_modules.h" 2

進階:手動指定標頭檔路徑(不想安裝系統套件時)

# 假設你將 pam 源碼編譯安裝至 /opt/pam
export CFLAGS="-I/opt/pam/include"
export LDFLAGS="-L/opt/pam/lib -lpam"
./configure --with-pam=/opt/pam

常見誤區

  • 裝了 libpam0g 卻還是報錯:那是執行期庫,需安裝 libpam0g-dev(Debian/Ubuntu)或 pam-devel(RHEL 系)。
  • 交叉編譯環境:確保目標架構的 pam-devel 已安裝在 sysroot 中(如 /opt/toolchain/arm-linux-gnueabihf/sysroot/usr/include/security)。
  • 容器環境:dockerfile 中加入 RUN apt-get update && apt-get install -y libpam0g-dev(或對應基底映像指令)。

總結

缺少 security/pam_modules.h 純屬開發套件未裝,對應發行版安裝 pam-devel / libpam0g-dev 即可秒解。記得同步安裝 gcc、make 等建置工具鏈,避免後續報錯。

Copyright © Windows教程網 All Rights Reserved