1. 程式人生 > 實用技巧 >使用VS2017編譯OpenSSL.0.9.8g

使用VS2017編譯OpenSSL.0.9.8g

環境:

  win10_x64家庭中文版,VS2017旗艦版

開始:

一、安裝工具

  1. 安裝ActivePerl

  2. 安裝nasm

  驗證安裝是否安裝成功:

  perl -version

  nasm -v

二、下載原始碼

  1.openssl-OpenSSL_0_9_8g.tar.gz          解壓到D:/openssl-OpenSSL_0_9_8g

  檢視openssl版本:opensslv.h #define OPENSSL_VERSION_TEXT "OpenSSL 0.9.8g 19 Oct 2007"

三、編譯

  1. 編寫指令碼build.bat

@echo off

::Release,Debug
set BUILD_TYPE=%1%
if not "%BUILD_TYPE%" == "Release" if not "%BUILD_TYPE%" == "Debug" (
    echo "BUILD_TYPE:%BUILD_TYPE% ERROR"
    exit /b
)

::x86,x64
set PLATFORM=%2%
if not "%PLATFORM%" == "x86" if not "%PLATFORM%" == "x64" (
    echo "PLATFORM:%PLATFORM% ERROR"
    exit 
/b ) ::Dynamic,Static set LIBRARY=%3% if not "%LIBRARY%" == "Dynamic" if not "%LIBRARY%" == "Static" ( echo "LIBRARY:%LIBRARY% ERROR" exit /b ) set CURRENT_DIR=%~dp0 if exist "C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ( set BUILD_TOOL="C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build
" ) else if exist "C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ( set BUILD_TOOL="C:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ) else if exist "D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ( set BUILD_TOOL="D:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ) else if exist "D:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ( set BUILD_TOOL="D:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ) else if exist "E:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ( set BUILD_TOOL="E:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ) else if exist "E:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ( set BUILD_TOOL="E:\Program Files\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build" ) else ( echo "BUILD_TOOL ERROR" goto end ) echo "BUILD_TOOL=%BUILD_TOOL%" ::if not defined VS150COMNTOOLS ( if "%PLATFORM%" == "x86" ( call %BUILD_TOOL%\vcvars32.bat" ) if "%PLATFORM%" == "x64" ( call %BUILD_TOOL%\vcvars64.bat ) ::) if "%PLATFORM%" == "x86" ( if "%BUILD_TYPE%" == "Release" ( perl Configure VC-WIN32 no-asm --prefix=%CURRENT_DIR%%PLATFORM% ) if "%BUILD_TYPE%" == "Debug" ( perl Configure debug-VC-WIN32 no-asm --prefix=%CURRENT_DIR%%PLATFORM% ) ) else if "%PLATFORM%" == "x64" ( if "%BUILD_TYPE%" == "Release" ( perl Configure VC-WIN64A no-asm --prefix=%CURRENT_DIR%%PLATFORM% ) if "%BUILD_TYPE%" == "Debug" ( perl Configure debug-VC-WIN64A no-asm --prefix=%CURRENT_DIR%%PLATFORM% ) ) ::exit /b call ms\do_nasm.bat call ms\do_win64a.bat if "%LIBRARY%" == "Dynamic" ( ::動態庫 echo y|nmake -f ms\ntdll.mak clean call nmake -f ms\ntdll.mak call nmake -f ms\ntdll.mak test call nmake -f ms\ntdll.mak install ) else if "%LIBRARY%" == "Static" ( ::靜態庫 echo y|nmake -f ms\nt.mak clean call nmake -f ms\nt.mak call nmake -f ms\nt.mak test call nmake -f ms\nt.mak install )

  2. 編譯