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
# 編譯單文件
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。