minGW编译openssl1.1.1b过程
1.下载安装minGW
http://www.mingw.org/download/installer
官网下载安装器mingw-get-setup.exe,下载并安装。安装过程参考https://www.cnblogs.com/lidabo/p/8990348.html。为了防止以后使用时遇到莫名其妙的问题,组件全选安装了。
装完后 C:\MinGW\bin 下gcc g++都有了。设置完环境变量,cmd里看版本
gcc -v
gcc version 8.2.0 (MinGW.org GCC-8.2.0-3)
2.下载openssl1.1.1b源码,并解压到本地。
3.编译openssl
运行 C:\MinGW\msys\1.0\msys.bat 打开mingw命令行界面。cd到openssl源码根目录,执行
./config
报错:当前perl版本是5.8,openssl需要5.10
查看C:\MinGW\msys\1.0\bin\perl.exe 版本,确实是5.8
解决办法,升级perl:
a)http://www.cpan.org/src/5.0/ 下载perl新版本的源码,在mingw环境下进行编译。但编译失败,遇到找不到C库问题。问题现象同 https://segmentfault.com/q/1010000014530717
b)https://sourceforge.net/projects/perl-mingw/ 下载mingw的perl 新版本perl-5.24.0-mingw32.zip
解压到C:/MinGW/msys/1.0/perl下,在msys的etc/profile里指定路径,使新perl的bin在旧perl前面
if [ $MSYSTEM == MINGW32 ]; then
export PATH=".:/usr/local/bin:/perl/bin:/mingw/bin:/bin:$PATH"
else
再次执行 ./config 可以生成makefile文件了。
然后是
make
make install
在make时报错了:C:minGWmsysPerl.exe 找不到
解决办法:打开makefile,修改 PERL= 这行,把 \ 改为 /
PERL=C:/MinGW/msys/1.0/perl/bin/perl.exe
make编译到后面时报错了:
-lws2_32 -lgdi32 -lcrypt32
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: crypto/bio/b_addr.o:b_addr.c:(.text+0xa7): undefined reference to `getnameinfo'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: crypto/bio/b_addr.o:b_addr.c:(.text+0xb2a): undefined reference to `getaddrinfo'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: crypto/bio/b_addr.o:b_addr.c:(.text+0xc82): undefined reference to `getaddrinfo'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: crypto/bio/b_addr.o:b_addr.c:(.text+0x7c9): undefined reference to `freeaddrinfo'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: crypto/init.o:init.c:(.text+0x1b3): undefined reference to `GetModuleHandleEx'
c:/mingw/bin/../lib/gcc/mingw32/8.2.0/../../../../mingw32/bin/ld.exe: crypto/init.o:init.c:(.text+0xb94): undefined reference to `GetModuleHandleEx'
collect2.exe: error: ld returned 1 exit status
make[1]: *** [libcrypto.dll.a] Error 1
解决办法:
http://stackmirror.caup.cn/page/skv2amtonepc 参考这个帖子,应该是config时配置不对。
不使用默认配置,使用下面这个命令
./config no-asm shared --prefix=/home/openssl --openssldir=/home/openssl/ssl
再次make,make install均无报错。
生成的include和lib在 C:\MinGW\msys\1.0\home\openssl 下