Build OpenSSL with MS Visual C++

From OpenUru
Jump to: navigation, search

This article describes building the Win32 version of the OpenSSL libraries using the assembler and C++ complier from MS Visual Studio .NET 2003. These instructions should also work with most other versions of Visual C++, although you will need to adjust the paths to some of the files to suit. The instruction will indicate where this is likely to be necessary.


It is assumed that you already have Visual Studio (or Visual C++) installed. You may also need Netwide Assembler (NASM) - Ensure that the folder where nasm.exe is located in in your PATH variable.

You will also need Perl to build the make files. On a Windows machine you should download and install ActiveState Perl.

Download the latest openssl tarball from and unpack (e.g. using WinRAR) to a convenient location. You will need to run some commands from a command prompt so choose a location that you can navigate to easily from a command prompt.

Configure Perl

Create a separate, empty folder where you want the finished products to go. Again, make this easy to locate from a command prompt. We now need to tell Perl about this folder.

Open a command prompt, navigate to the folder containing the Open SSL sources and type the following command, where d:/my/openssl/dir is the name of the folder you just created:
perl Configure VC-WIN32 --prefix=d:/my/openssl/dir

Check nMake from the command prompt

If your Windows start menu includes a "Visual Studio xxx Command Prompt" then you should use that to open a command prompt and ignore the rest of this section.

Depending on how Visual Studio/Visual C++ is installed, you may need to set up the compiler to run from the command prompt. Type the following command with no arguments:
If nmake runs and you get a "fatal error U1001" then the compiler will run from the command prompt. If you get an error message that nmake is not a recognized command then you need to setup the compiler environment variables.

Find where your complier is installed and locate the vsvars32.bat file (may be vcvars32.bat in some versions). Now, from the command prompt run the batch file (the following is an example and the path will vary depending upon the compiler version, and the installation folder). The path may use folder names that include spaces, in which case they need to be enclosed in double quotes:
c:/"Program Files"/"Microsoft Visual Studio .NET 2003"/Common7/Tools/vsvars32.bat

Note: you must do this from the command prompt you are going to work in: Do not try to double click on the .bat file in Windows Explorer or use a different command window - it will not work!

Create the Make files

The following instructions assume that you will use the MASM assembler (usually included with Visual Studio or Visual C++) for speed. If you do not want to use the assembler, refer to the INSTALL.W32 file in OpenSSL source folder for alternative commands.

At the command prompt, navigate to the folder where you put the OpenSSL sources, e.g.:
d: cd my/openssl-0.9.8q

Now type the following command to build the make files:

Assuming everything is OK you should get a few screenfuls of text and return to the command prompt without errors. Now build the files using the following command:
nmake -f ms\ntdll.mak

This may take a few minutes to run depending on your computer speed, but you should see many pages of components being compiled or assembled.

Run the self-tests and "install" the finished products

Once everything has been built, check it by running the included set of test applications:
nmake -f ms\ntdll.mak test

You will see the test scenarios being run. If these look OK you're ready to export the finished libraries to the destination directory you created earlier and configured in Perl (the instructions in INSTALL.W32 refer to this as "installing OpenSSL"):
nmake -f ms\ntdll.mak install

View the directory and check that it contains the following folder structure:


There may also be a shortcut to the folder placed in the root. You're done! You can now the copy the contents of the folder to wherever it is convenient for your projects.