Windows XP Windows 7 Windows 2003 Windows Vista Windows 綜合教學 Linux 系統教學
Windows 10 Windows 8 Windows 2008 Windows NT Windows Server 電腦軟體教學
您现在的位置: Windows教程網 >> Windows教程 >  >> Linux 系統教學 >> Linux 教學

Windows 環境編譯安裝 OpenSSL 完整教學 (VS2005 + Perl)

編輯:Linux 教學

OpenSSL 在 Windows 上需自行編譯方能獲得完整的開發庫與工具。本文記錄在 Windows XP SP2 + Visual Studio 2005 + Perl 5.8.6 + OpenSSL 0.9.8 環境下,從準備、配置、編譯到開發環境設定的完整流程,並整理常見錯誤對策。

一、預先安裝準備

1. Visual Studio 2005

VC++ 6.0 編譯 OpenSSL 常缺少 ml.exe、cl.exe 且出現 MASM 錯誤,建議直接使用 VS2005。

2. ActivePerl 5.8.6

下載:ActiveState 官網
安裝路徑預設 C:\Perl。較新版本可能相容性較差,測試階段建議用 5.8.6。

3. OpenSSL 0.9.8 原始碼

下載:OpenSSL 官網
產品開發請用最新版;測試階段舊版相容性較好。
若僅需使用而非開發,可直接下載預編譯二進制:官方相關二進制頁。

二、編譯安裝步驟

  1. 解壓至系統盤:如 C:\OpenSSL
  2. 配置 Win32 環境:
    CMD 進入 C:\OpenSSL,執行 perl Configure VC-WIN32
  3. 設定 VC 環境變數:
    進入 VS 安裝目錄 VC\Bin,執行 VCVARS32.BAT
  4. 產生 makefile:
    回到 C:\OpenSSL,執行 ms\do_ms(不使用組語)
    若報錯可嘗試:ms\do_masm(MASM)、ms\do_nasm(NASM)、ms\do_nt
  5. 執行編譯:
    nmake -f ms\ntdll.mak
    成功後輸出於 out32dll:libeay32.dll, libeay32.lib, ssleay32.dll, ssleay32.lib, openssl.exe
  6. 加入系統 PATH(需使用 openssl 指令時):
    將 C:\OpenSSL\out32dll 加入環境變數 Path

三、Visual Studio 開發環境設定

  1. Tools → Options → Projects and Solutions → VC++ Directories
    Include files 加入 C:\OpenSSL\inc32
    Library files 加入 C:\OpenSSL\out32dll
  2. 原始碼包含頭檔並連結庫:
    #include <openssl/ssl.h>
    #include <openssl/err.h>
    #include <openssl/bio.h>
    #pragma comment(lib, "libeay32.lib")
    #pragma comment(lib, "ssleay32.lib")
    

四、常見編譯錯誤與解決

錯誤現象解決方案
NMAKE 不被辨識使用「Visual Studio 2005 Command Prompt」啟動 CMD,或將 C:\Program Files\Microsoft Visual Studio 8\VC\bin 加入 PATH
fatal error U1077: 'cl'/'ml'/'link'參考 此篇分析,通常為環境變數或路徑問題
POSIX name deprecated... _read 導致 /WX 錯誤編輯 ms\ntdll.mak,移除 CFLAG 中的 /WX 旗標
_md5_block_asm_host_order unresolved external改用 ms\do_masm 產生 makefile 重新編譯

參考資源

  • OpenSSL 官方 FAQ 與 install.w32/install.w64 文件(直接拖入瀏覽器閱讀)
  • VS2005 控制台捷徑:開始 → Microsoft Visual Studio 2005 → Visual Studio Tools → Visual Studio 2005 Command Prompt
Copyright © Windows教程網 All Rights Reserved