windows下openssl编译

Posted 太白的技术博客

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了windows下openssl编译相关的知识,希望对你有一定的参考价值。

昨晚,在编译rabbitmq-c时,使用cmake生成vs项目文件时遇到下列错误:

CMake Error at C:/Program Files/CMake/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the
system variable OPENSSL_ROOT_DIR (missing: OPENSSL_LIBRARIES
OPENSSL_INCLUDE_DIR) (Required is at least version "0.9.8")
Call Stack (most recent call first):
C:/Program Files/CMake/share/cmake-3.6/Modules/FindPackageHandleStandardArgs.cmake:388 (_FPHSA_FAILURE_MESSAGE)
C:/Program Files/CMake/share/cmake-3.6/Modules/FindOpenSSL.cmake:380 (find_package_handle_standard_args)
CMakeLists.txt:273 (find_package)

经查,需要源码安装openssl以及需要相关头文件(为了简单起见,用过直接下载二进制版,不行)。故下载openssl 0.9.8g进行编译。

首先确保安装ActivePerl。

1、perl Configure VC-WIN32 no-asm

必须指定no-asm,不然后边很多编译会报错,指定--prefix=E:\\openssl可以安装到相应的目录。

2、ms\\do_nasm.bat

ms子目录下生成nt.make和ntdll.make文件,由于指定了no-asm,所以在这里必须是do_nasm而不是do_ms。

3、nmake -f ms\\ntdll.mak

4、nmake -f ms\\ntdll.mak install  #安装到prefix指定的目录


Microsoft (R) 程序维护实用工具 11.00.50727.1 版
版权所有 (C) Microsoft Corporation。保留所有权利。

Building OpenSSL
perl util/mkdir-p.pl E:\\openssl
perl util/mkdir-p.pl E:\\openssl\\bin
created directory `E:/openssl/bin\'
perl util/mkdir-p.pl E:\\openssl\\include
created directory `E:/openssl/include\'
perl util/mkdir-p.pl E:\\openssl\\include\\openssl
created directory `E:/openssl/include/openssl\'
perl util/mkdir-p.pl E:\\openssl\\lib
created directory `E:/openssl/lib\'
perl util/copy.pl inc32\\openssl\\*.[ch] E:\\openssl\\include\\openssl
Copying: inc32/openssl/aes.h to E:/openssl/include/openssl/aes.h
Copying: inc32/openssl/applink.c to E:/openssl/include/openssl/applink.c
Copying: inc32/openssl/asn1.h to E:/openssl/include/openssl/asn1.h
Copying: inc32/openssl/asn1_mac.h to E:/openssl/include/openssl/asn1_mac.h
Copying: inc32/openssl/asn1t.h to E:/openssl/include/openssl/asn1t.h
Copying: inc32/openssl/bio.h to E:/openssl/include/openssl/bio.h
Copying: inc32/openssl/blowfish.h to E:/openssl/include/openssl/blowfish.h
Copying: inc32/openssl/bn.h to E:/openssl/include/openssl/bn.h
Copying: inc32/openssl/buffer.h to E:/openssl/include/openssl/buffer.h
Copying: inc32/openssl/cast.h to E:/openssl/include/openssl/cast.h
Copying: inc32/openssl/comp.h to E:/openssl/include/openssl/comp.h
Copying: inc32/openssl/conf.h to E:/openssl/include/openssl/conf.h
Copying: inc32/openssl/conf_api.h to E:/openssl/include/openssl/conf_api.h
Copying: inc32/openssl/crypto.h to E:/openssl/include/openssl/crypto.h
Copying: inc32/openssl/des.h to E:/openssl/include/openssl/des.h
Copying: inc32/openssl/des_old.h to E:/openssl/include/openssl/des_old.h
Copying: inc32/openssl/dh.h to E:/openssl/include/openssl/dh.h
Copying: inc32/openssl/dsa.h to E:/openssl/include/openssl/dsa.h
Copying: inc32/openssl/dso.h to E:/openssl/include/openssl/dso.h
Copying: inc32/openssl/dtls1.h to E:/openssl/include/openssl/dtls1.h
Copying: inc32/openssl/e_os2.h to E:/openssl/include/openssl/e_os2.h
Copying: inc32/openssl/ebcdic.h to E:/openssl/include/openssl/ebcdic.h
Copying: inc32/openssl/ec.h to E:/openssl/include/openssl/ec.h
Copying: inc32/openssl/ecdh.h to E:/openssl/include/openssl/ecdh.h
Copying: inc32/openssl/ecdsa.h to E:/openssl/include/openssl/ecdsa.h
Copying: inc32/openssl/engine.h to E:/openssl/include/openssl/engine.h
Copying: inc32/openssl/err.h to E:/openssl/include/openssl/err.h
Copying: inc32/openssl/evp.h to E:/openssl/include/openssl/evp.h
Copying: inc32/openssl/hmac.h to E:/openssl/include/openssl/hmac.h
Copying: inc32/openssl/idea.h to E:/openssl/include/openssl/idea.h
Copying: inc32/openssl/krb5_asn.h to E:/openssl/include/openssl/krb5_asn.h
Copying: inc32/openssl/kssl.h to E:/openssl/include/openssl/kssl.h
Copying: inc32/openssl/lhash.h to E:/openssl/include/openssl/lhash.h
Copying: inc32/openssl/md2.h to E:/openssl/include/openssl/md2.h
Copying: inc32/openssl/md4.h to E:/openssl/include/openssl/md4.h
Copying: inc32/openssl/md5.h to E:/openssl/include/openssl/md5.h
Copying: inc32/openssl/obj_mac.h to E:/openssl/include/openssl/obj_mac.h
Copying: inc32/openssl/objects.h to E:/openssl/include/openssl/objects.h
Copying: inc32/openssl/ocsp.h to E:/openssl/include/openssl/ocsp.h
Copying: inc32/openssl/opensslconf.h to E:/openssl/include/openssl/opensslconf.h
Copying: inc32/openssl/opensslv.h to E:/openssl/include/openssl/opensslv.h
Copying: inc32/openssl/ossl_typ.h to E:/openssl/include/openssl/ossl_typ.h
Copying: inc32/openssl/pem.h to E:/openssl/include/openssl/pem.h
Copying: inc32/openssl/pem2.h to E:/openssl/include/openssl/pem2.h
Copying: inc32/openssl/pkcs12.h to E:/openssl/include/openssl/pkcs12.h
Copying: inc32/openssl/pkcs7.h to E:/openssl/include/openssl/pkcs7.h
Copying: inc32/openssl/pq_compat.h to E:/openssl/include/openssl/pq_compat.h
Copying: inc32/openssl/pqueue.h to E:/openssl/include/openssl/pqueue.h
Copying: inc32/openssl/rand.h to E:/openssl/include/openssl/rand.h
Copying: inc32/openssl/rc2.h to E:/openssl/include/openssl/rc2.h
Copying: inc32/openssl/rc4.h to E:/openssl/include/openssl/rc4.h
Copying: inc32/openssl/ripemd.h to E:/openssl/include/openssl/ripemd.h
Copying: inc32/openssl/rsa.h to E:/openssl/include/openssl/rsa.h
Copying: inc32/openssl/safestack.h to E:/openssl/include/openssl/safestack.h
Copying: inc32/openssl/sha.h to E:/openssl/include/openssl/sha.h
Copying: inc32/openssl/ssl.h to E:/openssl/include/openssl/ssl.h
Copying: inc32/openssl/ssl2.h to E:/openssl/include/openssl/ssl2.h
Copying: inc32/openssl/ssl23.h to E:/openssl/include/openssl/ssl23.h
Copying: inc32/openssl/ssl3.h to E:/openssl/include/openssl/ssl3.h
Copying: inc32/openssl/stack.h to E:/openssl/include/openssl/stack.h
Copying: inc32/openssl/store.h to E:/openssl/include/openssl/store.h
Copying: inc32/openssl/symhacks.h to E:/openssl/include/openssl/symhacks.h
Copying: inc32/openssl/tls1.h to E:/openssl/include/openssl/tls1.h
Copying: inc32/openssl/tmdiff.h to E:/openssl/include/openssl/tmdiff.h
Copying: inc32/openssl/txt_db.h to E:/openssl/include/openssl/txt_db.h
Copying: inc32/openssl/ui.h to E:/openssl/include/openssl/ui.h
Copying: inc32/openssl/ui_compat.h to E:/openssl/include/openssl/ui_compat.h
Copying: inc32/openssl/x509.h to E:/openssl/include/openssl/x509.h
Copying: inc32/openssl/x509_vfy.h to E:/openssl/include/openssl/x509_vfy.h
Copying: inc32/openssl/x509v3.h to E:/openssl/include/openssl/x509v3.h
perl util/copy.pl out32dll\\openssl.exe E:\\openssl\\bin
Copying: out32dll/openssl.exe to E:/openssl/bin/openssl.exe
perl util/copy.pl apps\\openssl.cnf E:\\openssl
Copying: apps/openssl.cnf to E:/openssl/openssl.cnf
perl util/copy.pl out32dll\\ssleay32.dll E:\\openssl\\bin
Copying: out32dll/ssleay32.dll to E:/openssl/bin/ssleay32.dll
perl util/copy.pl out32dll\\libeay32.dll E:\\openssl\\bin
Copying: out32dll/libeay32.dll to E:/openssl/bin/libeay32.dll
perl util/copy.pl out32dll\\ssleay32.lib E:\\openssl\\lib
Copying: out32dll/ssleay32.lib to E:/openssl/lib/ssleay32.lib
perl util/copy.pl out32dll\\libeay32.lib E:\\openssl\\lib
Copying: out32dll/libeay32.lib to E:/openssl/lib/libeay32.lib

生成的动态和静态库名为:libeay32.dll,libeay32.lib,ssleay32.dll,ssleay32.lib,以及openssl.exe。

相关错误:

第三步如果报:

.\\crypto\\cversion.c(105) : error C2220: 警告被视为错误 - 没有生成“object”文件
.\\crypto\\cversion.c(105) : warning C4129: “o”: 不可识别的字符转义序列
NMAKE : fatal error U1077: “"C:\\Program Files (x86)\\Microsoft Visual Studio 11.0\\VC\\BIN\\cl.EXE"”: 返回代码“0x2”
Stop.

则打开ms\\ntdll.mak文件,将其中的/WX去掉,如下:

如果报:

f:\\Microsoft Visual Studio 10.0\\VC\\INCLUDE\\errno.h(92) : error C2220: warning treated as error - no \'object\' file generated

f:\\Microsoft Visual Studio 10.0\\VC\\INCLUDE\\errno.h(92) : warning C4005: \'EADDRINUSE\' : macro redefinition
        tmp32dll\\e_os.h(153) : see previous definition of \'EADDRINUSE\'
NMAKE : fatal error U1077: \'"f:\\Microsoft Visual Studio 10.0\\VC\\BIN\\cl.EXE"\' : return code \'0x2\' Stop.

则:.打开errno.h文件,找到第92行,注释掉#define EADDRINUSE      100

如果报\'nmake\' 不是内部或外部命令,也不是可运行的程序或批处理文件,则使用VS自带的cmd,如下:

 

参考:

http://blog.csdn.net/eclipser1987/article/details/17588041

http://www.cnblogs.com/yidev/p/6373283.html

http://blog.163.com/lvan100@yeah/blog/static/68117214201332761143157/

http://shikezhi.com/html/2016/windows_0608/1140879.html

http://blog.csdn.net/pony_maggie/article/details/8588888

http://www.cnblogs.com/yidev/p/6373283.html

https://www.openssl.org/source/old/0.9.x/

http://blog.csdn.net/lg1259156776/article/details/52529704

至于其他的很多,纯属瞎扯淡。

以上是关于windows下openssl编译的主要内容,如果未能解决你的问题,请参考以下文章

windows下openssl编译

windows环境下VS2013编译openSSL

如何在 Windows 下编译 OpenSSL

如何在Windows下编译OpenSSL

如何在 Windows 下编译 OpenSSL

如何在 Windows 下编译 OpenSSL