C++ Based OPC UA Client/Server/PubSub SDK  1.7.6.537
Compiling OpenSSL with Visual Studio

The following sections describes how to compile OpenSSL 1.1.x for Visual Studio 2008 and higher without patented algorithms.

Requirements

CMake version >= 3.7
NASM (https://www.nasm.us/)
Perl (https://www.activestate.com/products/activeperl/)

Download and Unpack OpenSSL

Download the latest version of OpenSSL from here http://www.openssl.org/source/
Extract the OpenSSL tar to <SDK Installation Directory>\third-party\build_ssl.
That will create a new folder <SDK Installation Directory>\third-party\build_ssl\openssl-<version_number>.

Create a batch file to setup the environment

Navigate to <SDK Installation Directory>\third-party\build_ssl and create a new file env_no_VS.bat with the following content:

@echo off
set OPENSSL_VERSION=1.1.1j
PATH=C:\WINDOWS;C:\WINDOWS\system32;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\ REM PATH for Perl
where /q "C:\Perl\bin:perl.exe"
if errorlevel 1 (
where /q "C:\Perl64\bin:perl.exe"
if errorlevel 1 (
echo perl cannot be found. please ensure it is installed and placed in your path.
pause
exit /b
) else (
PATH=C:\Perl64\bin;C:\Perl64\site\bin;%PATH%
)
) else (
PATH=C:\Perl\bin;C:\Perl\site\bin;%PATH%
)
REM PATH for NASM
where /q "C:\Program Files (x86)\NASM:nasm.exe"
if errorlevel 1 (
where /q "C:\Program Files\NASM:nasm.exe"
if errorlevel 1 (
echo nasm cannot be found. please ensure it is installed and placed in your path.
pause
exit /b
) else (
PATH=C:\Program Files\NASM;%PATH%
)
) else (
PATH=C:\Program Files ^(x86^)\NASM;%PATH%
)
SET INCLUDE=
SET LIB=
SET LIBPATH=

That will setup the environment you need to use the following build scripts.

Create a batch file for your Visual Studio version

The following example code uses paths for VS2015. For other versions of Visual Studio you need to adapt the paths. Create a folder <SDK Installation Directory>\third-party\build_ssl\vs2015. In that folder create the following batch files.

To build 32bit debug libraries create the file build_win32_vs2015_debug.cmd:

@echo off
setlocal
call ..\env_no_VS.bat
REM setup environment
set VS_ENV_BAT="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat"
set BUILD_CONFIG=win32-vs2015-debug
set CONFIG_ARCH=debug-VC-WIN32
set REPLACE_ARCH=
set DEBUG_POSTFIX=d
CALL %VS_ENV_BAT%
REM create a copy of the source dir
xcopy ..\openssl-%OPENSSL_VERSION% openssl-%BUILD_CONFIG%\ /s /e
REM set target dir
set TARGET_DIR=%cd%\openssl-%OPENSSL_VERSION%-%BUILD_CONFIG%-DLL
cd openssl-%BUILD_CONFIG%
REM prefix is the target directory
perl Configure no-idea no-mdc2 no-rc5 no-ssl2 no-ssl3 %CONFIG_ARCH% --prefix=%TARGET_DIR%
REM replace version
powershell -Command "(gc makefile) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libcrypto.lib', 'libcrypto%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl.lib', 'libssl%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc configdata.pm) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File configdata.pm"
powershell -Command "(gc configdata.pm) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File configdata.pm"
nmake build_libs
REM for some reason the makefile sometimes gets corrupted after the build - so this is just a workaround
perl Configure no-idea no-mdc2 no-rc5 no-ssl2 no-ssl3 %CONFIG_ARCH% --prefix=%TARGET_DIR%
powershell -Command "(gc makefile) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libcrypto.lib', 'libcrypto%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl.lib', 'libssl%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc configdata.pm) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File configdata.pm"
powershell -Command "(gc configdata.pm) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File configdata.pm"
nmake install_dev
REM delete build directory
cd ..
RMDIR /S /Q openssl-%BUILD_CONFIG%

To build 32bit release libraries create the file build_win32_vs2015_release.cmd:

@echo off
setlocal
call ..\env_no_VS.bat
REM setup environment
set VS_ENV_BAT="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\vcvars32.bat"
set BUILD_CONFIG=win32-vs2015-release
set CONFIG_ARCH=VC-WIN32
set REPLACE_ARCH=
set DEBUG_POSTFIX=
CALL %VS_ENV_BAT%
REM create a copy of the source dir
xcopy ..\openssl-%OPENSSL_VERSION% openssl-%BUILD_CONFIG%\ /s /e
REM set target dir
set TARGET_DIR=%cd%\openssl-%OPENSSL_VERSION%-%BUILD_CONFIG%-DLL
cd openssl-%BUILD_CONFIG%
REM prefix is the target directory
perl Configure no-idea no-mdc2 no-rc5 no-ssl2 no-ssl3 %CONFIG_ARCH% --prefix=%TARGET_DIR%
REM replace version
powershell -Command "(gc makefile) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libcrypto.lib', 'libcrypto%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl.lib', 'libssl%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc configdata.pm) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File configdata.pm"
powershell -Command "(gc configdata.pm) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File configdata.pm"
nmake build_libs
REM for some reason the makefile sometimes gets corrupted after the build - so this is just a workaround
perl Configure no-idea no-mdc2 no-rc5 no-ssl2 no-ssl3 %CONFIG_ARCH% --prefix=%TARGET_DIR%
powershell -Command "(gc makefile) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libcrypto.lib', 'libcrypto%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl.lib', 'libssl%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc configdata.pm) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File configdata.pm"
powershell -Command "(gc configdata.pm) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File configdata.pm"
nmake install_dev
REM delete build directory
cd ..
RMDIR /S /Q openssl-%BUILD_CONFIG%

To build 64bit debug libraries create the file build_win64_vs2015_debug.cmd:

@echo off
setlocal
call ..\env_no_VS.bat
REM setup environment
set VS_ENV_BAT="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
set BUILD_CONFIG=win64-vs2015-debug
set CONFIG_ARCH=debug-VC-WIN64A
set REPLACE_ARCH=-x64
set DEBUG_POSTFIX=d
CALL %VS_ENV_BAT%
REM create a copy of the source dir
xcopy ..\openssl-%OPENSSL_VERSION% openssl-%BUILD_CONFIG%\ /s /e
REM set target dir
set TARGET_DIR=%cd%\openssl-%OPENSSL_VERSION%-%BUILD_CONFIG%-DLL
cd openssl-%BUILD_CONFIG%
REM prefix is the target directory
perl Configure no-idea no-mdc2 no-rc5 no-ssl2 no-ssl3 %CONFIG_ARCH% --prefix=%TARGET_DIR%
REM replace version
powershell -Command "(gc makefile) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libcrypto.lib', 'libcrypto%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl.lib', 'libssl%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc configdata.pm) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File configdata.pm"
powershell -Command "(gc configdata.pm) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File configdata.pm"
nmake build_libs
REM for some reason the makefile sometimes gets corrupted after the build - so this is just a workaround
perl Configure no-idea no-mdc2 no-rc5 no-ssl2 no-ssl3 %CONFIG_ARCH% --prefix=%TARGET_DIR%
powershell -Command "(gc makefile) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libcrypto.lib', 'libcrypto%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl.lib', 'libssl%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc configdata.pm) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File configdata.pm"
powershell -Command "(gc configdata.pm) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File configdata.pm"
nmake install_dev
REM delete build directory
cd ..
RMDIR /S /Q openssl-%BUILD_CONFIG%

To build 64bit release libraries create the file build_win64_vs2015_release.cmd:

@echo off
setlocal
call ..\env_no_VS.bat
REM setup environment
set VS_ENV_BAT="C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\amd64\vcvars64.bat"
set BUILD_CONFIG=win64-vs2015-release
set CONFIG_ARCH=VC-WIN64A
set REPLACE_ARCH=-x64
set DEBUG_POSTFIX=
CALL %VS_ENV_BAT%
REM create a copy of the source dir
xcopy ..\openssl-%OPENSSL_VERSION% openssl-%BUILD_CONFIG%\ /s /e
REM set target dir
set TARGET_DIR=%cd%\openssl-%OPENSSL_VERSION%-%BUILD_CONFIG%-DLL
cd openssl-%BUILD_CONFIG%
REM prefix is the target directory
perl Configure no-idea no-mdc2 no-rc5 no-ssl2 no-ssl3 %CONFIG_ARCH% --prefix=%TARGET_DIR%
REM replace version
powershell -Command "(gc makefile) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libcrypto.lib', 'libcrypto%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl.lib', 'libssl%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc configdata.pm) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File configdata.pm"
powershell -Command "(gc configdata.pm) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File configdata.pm"
nmake build_libs
REM for some reason the makefile sometimes gets corrupted after the build - so this is just a workaround
perl Configure no-idea no-mdc2 no-rc5 no-ssl2 no-ssl3 %CONFIG_ARCH% --prefix=%TARGET_DIR%
powershell -Command "(gc makefile) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libcrypto.lib', 'libcrypto%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File makefile"
powershell -Command "(gc makefile) -replace 'libssl.lib', 'libssl%DEBUG_POSTFIX%.lib' | Out-File makefile"
powershell -Command "(gc configdata.pm) -replace 'libcrypto-1_1%REPLACE_ARCH%', 'libcrypto%DEBUG_POSTFIX%' | Out-File configdata.pm"
powershell -Command "(gc configdata.pm) -replace 'libssl-1_1%REPLACE_ARCH%', 'libssl%DEBUG_POSTFIX%' | Out-File configdata.pm"
nmake install_dev
REM delete build directory
cd ..
RMDIR /S /Q openssl-%BUILD_CONFIG%

Optional step - Create batch to build all (debug and release in 32bit and 64bit)

To execute all build scripts in one go create a batch file with the following content:

@echo off
call build_win32_vs2015_debug.cmd
call build_win32_vs2015_release.cmd
call build_win64_vs2015_debug.cmd
call build_win64_vs2015_release.cmd
echo Build VS2015 Done

Use batch files

Check if the OpenSSL version in env_no_VS.bat matches the version of OpenSSL you want to build. Edit env_no_VS.bat to set the correct version:

set OPENSSL_VERSION=1.1.1j
  • Open a command promp and navigate to <SDK Installation Directory>\third-party\build_ssl.
  • Execute the batch file env_no_VS.bat to configure the environment.
  • Enter the folder containing the build scripts e.g. vs2015
  • Execute the batch file build_all.cmd to build all or execute one of the files described above to build a single configuration of OpenSSL.

Copy the Libraries to the SDK Folder Structure

Finally, you need to copy the libaries and header files to the SDK folder structure. Create a folder named
<SDK Installation Directory>\third-party\win<32/64>\vs<version>\openssl

The folder might already exist if you built with the version of Visual Studio that you installed the SDK for.

  • Create a folder <SDK Installation Directory>\third-party\win<32/64>\vs<version>\openssl\inc32.
  • Copy the folder include\openssl from the build directory to the inc32 folder created above
  • Copy the following files preserving the folder structure:
    • out32dll\libcrypto.dll
      out32dll\libcrypto.lib
      out32dll\libssl.dll
      out32dll\libssl.lib
    • out32dll.dbg\libcryptod.dll
      out32dll.dbg\libcryptod.lib
      out32dll.dbg\libcryptod.pdb
      out32dll.dbg\libssld.dll
      out32dll.dbg\libssld.lib
      out32dll.dbg\libssld.pdb