How I compiled OpenSSL from sources with VS2015

I installed Perl, downloaded and extracted OpenSSL 1.1.0h and built 64 bit version in VS2015 x64 Native Tools Command Prompt with the following commands:

set PATH=%PATH%;C:\Perl64\bin
perl Configure VC-WIN64A no-asm
nmake

32 bit version can be built with VC-WIN32 configuration option as described in INSTALL:

on Windows (only pick one of the targets for configuration):
$ perl Configure { VC-WIN32 | VC-WIN64A | VC-WIN64I | VC-CE }
$ nmake
$ nmake test
$ nmake install

probably ‘A’ suffix means AMD and ‘I’ means something else, so we need ‘A’.

Without no-asm configuration option it requires NASM to be in paths (is now the only supported assembler):

set PATH=%PATH%;C:\PFiles\nasm-2.13.03-win64
set PATH=%PATH%;C:\Perl64\bin
perl Configure VC-WIN64A
nmake

The documentation says that no-asm option “Disables assembly language routines (and uses C routines)“, but actually uplink-x86_64.asm file is generated and compiled in 64 bit configuration (not in 32 bit):

set ASM=ml64
"C:\Perl64\bin\perl.exe" "ms\uplink-x86_64.pl" auto crypto\uplink-x86_64.asm
ml64 /c /Cp /Cx /Zi /Focrypto\uplink-x86_64.obj "crypto\uplink-x86_64.asm"

I also did:

perl Configure VC-WIN64A no-asm --prefix="%CD%\bin\Release\x64" --openssldir="%CD%\bin\Release\x64"
nmake
nmake install
nmake clean

This creates the following directories in bin\Release\x64 subfolder:

bin
certs
html
include
lib
misc
private
openssl.cnf
openssl.cnf.dist

bin directory contains *.dll, *.exe and *.pdb and include directory contains C++ headers.

32 bit and 64 bit configurations install different opensslconf.h heder file into include directory. At the beginning of the file 32 bit header defines OPENSSL_SYS_WIN32, 64 bit header defines OPENSSL_SYS_WIN64A, and at the end of the file BN_LLONG, SIXTY_FOUR_BIT, THIRTY_TWO_BIT defined differently. So we need separate include directories for 32 bit and 64 bit configurations.

To make OpenSSL build on our corporate server without Perl I extracted *.c files from Makefile using the following C# program:

using System;
using System.Text.RegularExpressions;

namespace ConvMak
{
class Program
{
static string cfilePattern = @"obj\s+\""(?<file>.+\.c)\""";

static Regex cfileRegex = new Regex(cfilePattern);

static void Main(string[] args)
{
if (!Console.IsInputRedirected)
{
Console.WriteLine("This program requires that input be redirected from a file.");

return;
}

while (true)
{
string line = Console.ReadLine();

if (line == null)
{
break;
}

Match m = cfileRegex.Match(line);

if (m.Success)
{
string file_name = m.Groups["file"].Value;

Console.WriteLine($"\t<ClCompile Include=\"..\\{file_name}\" />");
}
}
}
}
}

and manually added them to a newly created VS2015 project with the following settings:

Output Directory: $(SolutionDir)..\bin\$(Configuration)\$(Platform)\
Additional Include Directories: ..\;..\crypto\include;..\include;..\crypto\modes
Preprocessor Definitions: OPENSSL_USE_APPLINK DSO_WIN32 NDEBUG OPENSSL_THREADS OPENSSL_NO_STATIC_ENGINE OPENSSL_PIC OPENSSL_SYS_WIN32 WIN32_LEAN_AND_MEAN L_ENDIAN _CRT_SECURE_NO_DEPRECATE ENGINESDIR=”$(EscapedOutDir)\\lib\\engines-1_1″ OPENSSLDIR=”$(EscapedOutDir)”

where EscapedOutDir is an XML element added to the global property group:

<PropertyGroup Label="Globals">
...
<EscapedOutDir>$(SolutionDir.Replace('\', '\\'))..\\bin\\$(Configuration)\\$(Platform)</EscapedOutDir>
</PropertyGroup>

ASM file I included to the project as follows:

<ItemGroup>
<MASM Include="..\build\x64\crypto\uplink-x86_64.asm" Condition="'$(Platform)'=='x64'"/>
</ItemGroup>

1 Response to How I compiled OpenSSL from sources with VS2015

  1. laca says:

    Hi Dimitry,

    ..and ā€˜Iā€™ means something else..

    ‘I’ means Itanium

    Thanks for this post. It was very useful.

    Cheers,
    /laca

Leave a Reply

Your email address will not be published. Required fields are marked *