用VistualStudio编译OpenSSL

2019-07-08 又一次更新
这次是为了升级到可以支持TLS1.3,所以又要编译OpenSSL,再次记录一下。

  • 不能再用VS2005编译了,我怎么试验也不行。手头现成的VS是2012所以就以它为示例
  • 首先就是要安装ActivePerl
  • 启动 Developer Command Prompt For VS2012
  • 然后运行如下命令
    > perl Configure VC-WIN32 #生成Makefile
    > nmake #直接编译,以前会调用ms\do_ms之类的,新的OpenSSL中没有这东西了
    

这样就OK了

这之后在把编译好的库放入原来的工程中编译的时候又出问题了,主要是编译选项的Runtime Library:MDD MTD MD MT这个有冲突。那么这种冲突如何解决呢?以MD改MT为例

  • 找到目录下生成的Makefile
  • 搜索MD (CFLAGS中的),找到后改成MT
  • 重新 nmake

就可以了


下面那一大堆都是自己以前的记录,但是前几天在翻看OpenSSL的源代码的时候突然想调试一下,所以就想着怎么用编出给VS调试用的OpenSSL Library。虽然后来没有实现自己的想法,不过找到一个不错的网站,上面有已经编译好的OpenSSL的Library还有编译方法。相比我的记录就更加全面了,所以记录一下。

Building OpenSSL with Visual Studio


@1

  1. Uncompress the openssl-1.0.1c.tar.gz, For example at C:\openssl-1.0.1c
  2. Install the ActivePerl
  3. Use the VS2005 Command Prompt
    Start->All Programs->Microsoft Vistual Studio 2005->Visual Studio Tools->Visual Studio 2005 Command Prompt
> perl configure VC-WIN32
> ms\do_ms

If you want to build the dlls, input:

> nmake -f ms\ntdll.mak

if you want to build the libs, input:

> nmake -f ms\nt.mak
  1. when the compiling is finished, you can find the dll&exe in folder or you can find the lib&exe in folder.
  2. If you want use openssl api in you project, please include the folder in you project.

@2

OpenSSL 1.0.1k compile error

I try to buld openssl-1.0.1k with Visual Studio...

> PERL Configure VC-WIN32... 
> ms\do_nasm 
> NMAKE -f ms\nt.mak 

and have one error:

.\crypto\cversion.c(80) : error C2065: 'cflags' : undeclared identifier

Simple patch:

diff U3 a/openssl-1.0.1k/crypto/cversion.c b/openssl-1.0.1k/crypto/cversion.c 
--- a/openssl-1.0.1k/crypto/cversion.c  Thu Jan 08 08:00:56 2015 
+++ b/openssl-1.0.1k/crypto/cversion.c  Thu Jan 08 10:16:03 2015 
@@ -77,7 +77,7 @@ 
    if (t == SSLEAY_CFLAGS) 
     { 
 #ifdef CFLAGS 
-    return(cflags); 
+    return(CFLAGS); 
 #else 
     return("compiler: information not available"); 
 #endif 

@3

OpenSSL 1.0.2e compile error

Building 1.0.2e has error

Assembling: tmp32\sha1-586.asm
tmp32\sha1-586.asm(1432) : error A2070:invalid instruction operands
tmp32\sha1-586.asm(1576) : error A2070:invalid instruction operands
NMAKE : fatal error U1077: "C:\Program Files (x86)\Microsoft Visual Studio 10.
0\VC\BIN\ml.EXE": return code "0x1"

The all asm SHOULD use NASM to build, so use NASM to replace the MS:

  1. Install the NASM, download from http://www.nasm.us/
  2. Add the NASM path to the $PATH

Build the OpenSSL:

> perl configure VC-WIN32
> ms\do_nasm
> nmake -f ms\nt.mak

你可能感兴趣的:(用VistualStudio编译OpenSSL)