首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式碼之家 >> 編程語言 >  >> C語言 >> 關於C語言

Linux 編譯報錯 openssl/md5.h 找不到:一條命令解決缺少開發包

     編輯:關於C語言

錯誤現象


fatal error: openssl/md5.h: No such file or directory
 #include 
          ^~~~~~~~~~~~~~~
compilation terminated.

根本原因

系統安裝了 OpenSSL **運行時庫** (openssl-libs),但**缺少開發包** (openssl-devel),導致頭文件 md5.h、sha.h 等及靜態庫 libcrypto.a 不存在。

解決命令


# CentOS / RHEL / Fedora / Rocky / AlmaLinux
sudo yum install openssl-devel

# 或 dnf (Fedora 22+ / RHEL 8+)
sudo dnf install openssl-devel

# Ubuntu / Debian
sudo apt-get update && sudo apt-get install libssl-dev

# openSUSE
sudo zypper install libopenssl-devel

# Arch Linux
sudo pacman -S openssl

驗證安裝


# 檢查頭文件
ls /usr/include/openssl/md5.h
# 檢查庫文件
ls /usr/lib64/libcrypto.so
# 編譯測試
gcc -lcrypto test_md5.c -o test_md5

補充:編譯鏈接 OpenSSL 程序


# 編譯單文件
gcc main.c -o main -lcrypto

# Makefile 片段
CFLAGS += $(shell pkg-config --cflags openssl)
LDLIBS += $(shell pkg-config --libs openssl)

# CMakeLists.txt
find_package(OpenSSL REQUIRED)
target_link_libraries(my_target OpenSSL::SSL OpenSSL::Crypto)

總結

運行時庫 ≠ 開發包。凡遇 xxx.h not found 且屬系統庫,**優先安裝對應 `-devel` / `-dev` 包**。OpenSSL 極常用,建議基礎環境預裝 openssl-devel / libssl-dev。

  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式碼之家 All Rights Reserved