用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 <openssl-1.0.1c/out32dll> folder or you can find the lib&exe in <openssl-1.0.1c/out32> folder.
  2. If you want use openssl api in you project, please include the <openssl-1.0.1c/inc32> 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
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容