OpenSSL源码编译安装
无论在什么平台,OpenSSL的编译一般需要经过三个步骤:
- 使用Configure批处理,根据平台环境、选用的编译器及其他参数设置编译的环境变量。
- 通过使用批处理指令来根据上面设置好的环境变量生成编译脚本文件。
- 使用特定的编译指令进行编译链接。
本文将介绍OpenSSL在Linux、Windows、Android、Mac和iOS平台的编译方式。
一、OpenSSL在Linux平台的编译
打包环境
需要安装perl、make和gcc。
源码准备
编译安装
- 执行config
./config --prefix=/home/workspace/openssl/output/64
./config -t
- 执行make
make
执行结果:
- 执行make test
make test
执行结果:
- 执行make install
make install
执行完成后,编译生成的文件将会放到/home/workspace/openssl/output/64目录下:
二、OpenSSL在Windows平台的编译
打包环境
编译工具:Visual Studio 2019
INSTALL文件说明了OpenSSL在Windows编译的方式:
NOTES.WIN文件说明了编译需要的额外依赖工具,我们需要下载安装这些工具,并配置环境变量:
编译32位库
- 打开[x86 Native Tools Command Prompt for VS 2019]:【开始】-【所有程序】—【Microsoft visual studio2019】—【x86 Native Tools Command prompt for VS 2019】(以管理员身份运行)
- 切换到OpenSSL源码目录
- 执行编译
#第一步
#若需要编译静态库需要增加no-shared参数,否则默认生成动态库
#perl Configure VC-WIN32 no-shared --prefix=C:\Users\Username\Desktop\openssl\output\32
perl Configure VC-WIN32 --prefix=C:\Users\Username\Desktop\openssl\output\32
#第二步
nmake
#第三步
nmake test
#第四步
nmake install
编译完成的目标文件:
编译64位库
- 打开[x64 Native Tools Command Prompt for VS 2019]:【开始】-【所有程序】—【Microsoft visual studio2019】—【x64 Native Tools Command Prompt for VS 2019】(以管理员身份运行)
- 切换到OpenSSl源码目录
- 执行编译
#第一步
#若需要编译静态库需要增加no-shared参数,否则默认生成动态库
#perl Configure VC-WIN64A no-shared --prefix=C:\Users\Username\Desktop\openssl\output\64
perl Configure VC-WIN64A --prefix=C:\Users\Username\Desktop\openssl\output\64
#第二步
nmake
#第三步
nmake test
#第四步
nmake install
编译完成的目标文件:
错误处理
注意:若在执行perl Configure VC-WIN32 --prefix=C:\Users\Username\Desktop\openssl\output\32或perl Configure VC-WIN64A --prefix=C:\Users\Username\Desktop\openssl\output\64时出现下列错误
It looks like you don't have either nmake.exe or