标签:
今天有一个项目需要使用到 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
下面摘自其 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
标签:
原文地址:http://www.cnblogs.com/personnel/p/4584941.html