前言
目前网络上许多构建Curl和OpenSSL的教程都是很老的,并且大多数教程都是针对VS IDE进行构建。对于MinGW版本的Curl库构建,资料都很少。我从网络资料得到启发,根据项目中的指引,最终将MinGW版本的Curl和OpenSSL都构建了出来,在此记录当作备份和交流
实战
资料准备
- Curl库源码包:官网下载链接
本文使用7.83.1版本 - OpenSSL库源码包:Github仓库链接
本文使用3.1.0版本 - Msys1.0:SourceForge链接
本文使用1.0.11版本 - Perl for MinGW:SourceForge链接
本文使用5.24.0版本,你也可自行构建最新版本
环境准备
配置工具
- 安装Msys1.0【建议遵循默认设定安装到C盘中】,后续操作全部都在Msys中完成,不使用Win的CMD终端。
- 解压MinGW版本Perl到空闲目录
- 完成后打开msys.bat进入Msys环境,通过命令cat /etc/fstab查看开机自动挂载点的情况:
67566@BEN-WORKPC ~
$ cat /etc/fstab
#fstab.sample
#This is a sample file for /etc/fstab.
#Currently /etc/fstab is only read during dll initialization.
#I will eventually watch the directory for changes and reread the file.
#The line format is simple in that you give the Win32 path, followed by one or
#more space or tab delimiter, followed by the mount point. Mount points in
#typical UNIX environments must be a physical name on a drive before it can
#actually be used as a mount point. In this implementation the "must exist"
#requirement isn't enforced, however, it will be an aide to such programs as
#find and readline's tab completion if it does exist.
#You can use a # as the first character on the line as a comment indicator.
#Blank lines are ignored.
#Win32_Path Mount_Point
c:\\Qt\\Qt5.12.12\\Tools\\mingw730_32 /mingw
c:\\Users\\67566\\Downloads\\perl-5.24.0-mingw32\\perl-5.24.0 /perl
可以看到我分别将我对应Win盘符中的MinGW和MinGW版本的Perl路径挂载到了对应挂载点上
- c:\Qt\Qt5.12.12\Tools\mingw730_32
- c:\Users\67566\Downloads\perl-5.24.0-mingw32\perl-5.24.0
挂载点有两个:
- mingw
- perl
你需要将自己的MinGW和MinGW版本的Perl路径对应挂载上去
- 重新打开Msys环境,确认mingw32-make指令和perl指令可用,并且通过-v查看版本也对应的上
配置项目路径
将Curl源码包和OpenSSL源码包放置到Msys的home目录,确保进入这两个文件夹后,就是项目文件,而不是还有额外的子文件夹,以便后期进行构建工作
构建OpenSSL
- 在Msys环境中,进入OpenSSL项目文件夹
- 执行
- perl Configure mingw shared no-asm【构建动态库】
- perl Configure mingw no-shared no-asm【构建静态库】
这个操作会生成Makefile文件
- 修改Makefile中的此部分内容成以下格式,原先使用的是Win规则的路径,会导致构建出错
- 在OpenSSL项目文件夹,直接执行mingw32-make,构建OpenSSL所需库。构建完成后会得到以下文件【以动态库为例】:
- libssl.a 静态库
- libssl.dll.a 动态导入库
- libssl-x.dll 动态库,其中x会变成OpenSSL的大版本,比如libssl-3.dll
- libcrypto.a
- libcrypto.dll.a
- libcrypto-x.dll
- 在OpenSSL根目录新建out文件夹,将libssl.dll.a和libcrypto.dll.a分别改为libssl32.dll和libeay32.dll,放置到out文件夹中;同时新建outinc文件夹,将include文件夹中的内容复制到outinc。以便Curl项目能读取到OpenSSL的头文件及动态导入库
注意:老版本的OpenSSL库名称为libeay,libssl之类的,最新版的库已经更换名字
构建Curl
- 进入Curl项目目录
- 进入lib文件夹,修改Makefile.m32文件中的以下内容,进行OpenSSL路径的配置
- 构建curl,有两种方法:
- 在Curl项目根目录,执行mingw32-make mingw32-ssl
- 在Curl项目的lib目录,执行mingw32-make -f Makefile.m32 CFG=-ssl
- 构建成功后会生成:
- libcurl.a
- libcurl.dll.a
- libcurl.dll