windows & gcc & mingw & mysy 编译 openssl
今天有一个项目需要使用到 https, 以前一直用的都是http请求, 用 socket() 实现 https 请求我还真是头一回遇到。
先网上搜索了一下相关资料,明白了 https 相比较 http 就是多了一个认证,发送与接收的数据都是经过加密的,不能是明文。
然后说下载个openssl,用这个能实现https请求。
我平时很少用c写代码,再加上学习c的时候选了一条现在看来不是很理想的路(c & gcc & mingw & windows & codeblocks)
我到现在连基本的gcc 用法都不会。
花了一整天,终于完成 openssl在本地的编译,下面是我的操作步骤,收藏一下,不然下次又需要好久:
1. 下载 MinGW 和 MSYS,并安装 (可从http://www.mingw.org/下载, MSYS 也可以单独下载)
2. 下载 per 5.x, (百度搜索:ActivePerl , 就能下载)
3. 下载 openssl 源代码 (http://www.openssl.org/source/), 下载完成后可以解压缩到 C:\openssl-1.0.1g
4. 运行 MSYS 控制台: msys.bat
5. cd /c/openssl-1.0.1g (这是linux下的路径写法)
6. 编译方法见INSTALL 文件,以及INSTALL.WIN32文件
按说明书上,依次执行命令:(执行命令前,建议把360临时退出,编译速度会提高很多)
默认编译得到的是静态库:
$ ./config
$ make (在我电脑上耗时: 10分钟左右)
$ make test (在我电脑上耗时: 20分钟左右)
$ make install (在我电脑上耗时: 30分钟左右) 注意,执行这一命令前,需要修改一下 Makefile 文件。
编译动态库,只需添加参数 shared 即可:
$ ./config shared
$ make
$ make test
$ make install
----------------------------------------------------------------------------------------------------
注:2018-8-25 从官网下载了 openssl-1.0.2p.tar.gz,然后解压缩,编译动态库。
编译完动态库后,接着使用 ./config 来编译静态库的时候,生成的静态库中 bin\openssl.exe 有问题。
只好重新解压缩一下 openssl-1.0.2p.tar.gz,使用 ./config 来重新编译静态库,成功编译。
本来想下载最新版: openssl-1.1.1-pre9.tar.gz, 但看到官网介绍说 1.1.1 版将是LTS版本,目前正在开发中,主要关注的是实施TLSv1.3。
由于稳定版还没有发布,同时看到一篇文章(https://blog.csdn.net/lostspeed/article/details/69492531)说, 如果由原来的 1.0.2 升级到 1.1.1 原来的项目代码中涉及到 openssl 的部分代码需要改动,我就暂时放弃升级到 1.1.1
----------------------------------------------------------------------------------------------------
2018-8-27
试着对 openssl 进行瘦身(裁剪), 因为项目中使用静态库生成的exe文件因openssl增加了 1.5M。
参考网上的一些例子:
openssl 剪裁: http://www.169it.com/blog_article/841427108.html
Build openssl with just RSA and AES: https://stackoverflow.com/questions/7827836/build-openssl-with-just-rsa-and-aes
重新编译:
./config no-idea no-camellia no-seed no-bf no-cast no-des no-rc2 no-rc4 no-rc5 no-md2 no-md4 no-ripemd no-mdc2 no-ssl2 no-ssl3
运行结果提示:
Configured for mingw.
*** Because of configuration changes, you MUST do the following before
*** building:
make depend
然后根据提示,执行命令: make depend
making depend in crypto...
make[1]: Entering directory `/c/openssl-1.0.2p/crypto'
../util/domd: line 35: cc: command not found
make[1]: *** [local_depend] Error 1
make[1]: Leaving directory `/c/openssl-1.0.2p/crypto'
make: *** [depend] Error 1
关于这个问题,继续从网上找解决方案: http://openssl.6102.n7.nabble.com/OpenSSL-1-0-1c-Mac-OS-X-no-XXX-and-missing-make-depend-td42920.html
部分内容:
Open the Makefile generated by ./config. Its located in the root of
openssl-1.0.1x. Scroll down to line 75 or so. Change
MAKEDEPPROG=makedepend to:
MAKEDEPPROG=$(CC) -M
And some things that don't work:
MAKEDEPPROG=/usr/bin/gcc -M
MAKEDEPPROG=gcc -M
MAKEDEPPROG=llv-gcc -M
根据上面的英文提示:
修改 Makefile 文件, 将 MAKEDEPPROG=... 修改为 MAKEDEPPROG=$(CC) -M
然后重试: make depend
不会再显示错误信息了。
接下来: make
然后:make test
...
signed content test streaming BER format, DSA key: OK
signed content test streaming BER format, 2 DSA and 2 RSA keys: OK
signed content test streaming BER format, 2 DSA and 2 RSA keys, no attributes: OK
signed content test streaming S/MIME format, 2 DSA and 2 RSA keys: OK
signed content test streaming multipart S/MIME format, 2 DSA and 2 RSA keys: OK
enveloped content test streaming S/MIME format, 3 recipients: generation error
make[1]: *** [test_cms] Error 1
make[1]: Leaving directory `/c/openssl-1.0.2p/test'
make: *** [tests] Error 2
具体错误是什么,我没看明白。
最后:make install
瘦身的操作完工,这个时候我看了一下 lib 文件夹中的 libcrypto.a 和 libssl.a 文件大小显示:
libcrypto.a (2941KB)
libssl.a (539KB)
合计: 3.39M
我又去查看了一下不做任何瘦身操作生成的这两个文件的大小:
libcrypto.a (3180KB)
libssl.a (548KB)
合计:3.63M
也就是说通过 ./config no-idea no-camellia no-seed no-bf no-cast no-des no-rc2 no-rc4 no-rc5 no-md2 no-md4 no-ripemd no-mdc2 no-ssl2 no-ssl3
libcrypto.a 和 libssl.a 文件大小一共减少了 0.24M
我原来的项目 exe 文件大小: 2083KB,然后我用瘦身后的 openssl 重新编译我的项目,生成的 exe 文件大小:2010KB, 项目 exe 文件大小减少了 73KB。
总结:瘦身 openssl 的结果不太令我满意,只减少了 73KB。
----------------------------------------------------------------------------------------------------
下面摘自其 INSTALL 说明文件
Configuration Options
---------------------
There are several options to ./config (or ./Configure) to customize
the build: .....
shared In addition to the usual static libraries, create shared
libraries on platforms where it's supported. See "Note on
shared libraries" below.
make install完毕之后,会在D:\MinGW\msys\1.0\local\ssl的目录下找到openssl库,包括了头文件,dll文件等
---------------------------------------------------------------------------------
我在第一次执行 make install 时, 花了差不多30分钟执行完成,但最后抛出一个错误提示:
installing libcrypto.a
/bin/sh: line 5: CodeBlocksMinGWbin/ranlib.exe: No such file or directory
installing libssl.a
/bin/sh: line 5: CodeBlocksMinGWbin/ranlib.exe: No such file or directory
make: *** [install_sw] Error 1
看这个意思,是与 ranlib.exe 有关,没找到文件。
由于在 MYSY控制台,路径名都像 linux一样, 我打开 Makefile 文件,搜索: ranlib.exe
找到一行: RANLIB= \CodeBlocks\MinGW\bin/ranlib.exe
看这个文件名路径怪怪的,又有 '\', 又有 '/', 我搜索了一下本地电脑上的 ranlib.exe, 找到文件位置后, 我修改为:
RANLIB= /c/CodeBlocks/MinGW/bin/ranlib.exe (也就是 c:\CodeBlocks\MinGW\bin\ranlib.exe)
保存,然后重新执行 make install, 不会再抛出错误。
---------------------------------------------------------------------------------
相关资料:
mingw下编译openssl
http://blog.csdn.net/cibiren2011/article/details/10095021
用MinGW编译openssl
http://blog.csdn.net/feiyunw/article/details/5597546
MinGW编译支持openssl-1.0.0a的libcurl-7.21.3
http://blog.csdn.net/yui/article/details/6170889
How to build OpenSSL with MinGW in WIndows?
http://stackoverflow.com/questions/9379363/how-to-build-openssl-with-mingw-in-windows
在Windows下编译OpenSSL(VS2005)
http://lwglucky.blog.51cto.com/1228348/325483
2014-05-06
windows & gcc & mingw & mysy 编译 openssl的更多相关文章
- windows 平台使用 VS2017 编译openssl源码
windows 平台使用 VS2017 编译openssl源码 1)依赖安装 安装 perl 脚本解释器 下载 http://libevent.net/download 安装 nasm 汇编器 C:\ ...
- MinGW下编译openssl, json-c
目的:在windows环境下,编译开源库openssl 环境:windows 10 ,Mingw及自带msys工具,openssl-1.0.2j 工具主要使用MinGW(含msys1.0), IDE选 ...
- gcc for windows(mingw)编译多个c文件
myString.c myString.h main.c 其中,myString.c与myString.h对应,myString.h文件中是一些函数的声明,而myString.c文件中是.h文件中声明 ...
- Qt5.8 在windows下mingw静态编译
官方对编译一些条件介绍:https://doc.qt.io/qt-5/windows-requirements.html 在默认情况下,用QtCreator编译程序时,使用的是动态编译.编译好的程序在 ...
- windows环境下VS2013编译openSSL
openssl版本:1.0.2h 编译器:MSVC (VS2013) 需要准备工具:perl. windows环境的perl下载请戳这里:http://www.activestate.com/acti ...
- [转]Windows下使用VS2015编译openssl库
转自:http://blog.csdn.net/alger_magic/article/details/52584171 目标:编译vs环境下openssl库 工具: 1. 编译环境win10+vs2 ...
- Windows下MinGW跨平台编译和使用log4cpp
Log4cpp 是C++开源日志库,为 C++ 应用程序开发中提供了日志的追踪和调试功能,基于 LGPL 开源协议,移植自 java 的日志项目 log4j, 并在 api 上保持了一致性. 1. 环 ...
- VS2015编译OpenSSL
概述 OpenSSL 是一个开源的第三方库,它实现了 SSL(Secure SocketLayer)和 TLS(Transport Layer Security)协议,被广泛企业应用所采用.对于一般的 ...
- windows 平台使用 VS2017 编译 libevent 源码
一 依赖库编译 先要将其依赖的库编译好,其中openssl需要编译到libevent中,编译成libevent_openssl.lib库,zlib在新版本中只有示例用到. 1)windows 平台使用 ...
随机推荐
- 利用 John the Ripper 破解用户登录密码
一.什么是 John the Ripper ? 看到这个标题,想必大家都很好奇,John the Ripper 是个什么东西呢?如果直译其名字的话就是: John 的撕裂者(工具). 相比大家都会觉得 ...
- Scrum Meeting NO.7
Scrum Meeting No.7 1.会议内容 经过老师提醒,我们认识到,应尽快把主要功能实现,其他的细枝末节应在这之后慢慢添加.当今最重要的任务是和online组和数据处理组实现数据共享. 此外 ...
- 小学四则运算APP 第二次冲刺 第四天
团队成员:陈淑筠.杨家安.陈曦 团队选题:小学四则运算APP 第二次冲刺阶段时间:11.29~12.09 本次发布的是合并后的选择题功能界面的设置: ChoiceSet.java: package c ...
- react 动态获取数据
如果reander()里面的dom元素是动态获取的,就要将函数放到setSTATE()里面执行
- 量产救U盘
同事U盘不能格式化,快速格式化失败,非快速格式化也失败.就问谁有360安全软件,试试能不能格式化. 我说我有火绒,但是不知道火绒并没有格式化U盘的功能(应该没有吧,反正我找了以后没找到) 那怎么办呢? ...
- HDU 2087 剪花布条 (字符串哈希)
http://acm.hdu.edu.cn/showproblem.php?pid=2087 Problem Description 一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图 ...
- Linux Network Commands
https://www.tecmint.com/linux-network-configuration-and-troubleshooting-commands/ http://www.tldp.or ...
- Activiti启动某个流程失败,页面报500
现象:Activiti启动某个流程失败,页面报500,错误日志如下. 2017-06-19 10:50:09 [org.activiti.engine.impl.interceptor.Command ...
- error loading midas.dll问题
如果用的delphi在你的单元里用uses midaslib这个东西就可以把midas静态连接到你的程序楼上的也可以 在程序中使用winexec("regsvr32.exe midas.dl ...
- [kali] 安装完kali之后允许远程ssh
1. 安装kali 2.控制台登录kali 3. 修改 /etc/ssh/sshd_config 4.将 permitrootlogin 前面的注释去掉,并且后面改为yes 5.然后重启ssd服务 / ...