How to Compile OpenSSL for Visual Studio 2010/2012

We are using OpenSSL for secure communication because… well, anyone with an application communicating over any kind of network should use some kind of secure communication. OpenSSL is free and open source so it’s a good choice for many of the usual reasons.

OpenSSL is multiplatform and requires an on-site build. We are working with Visual Studio 2010 (now moving to 2012) and thus we need to compile it specifically for that environment. I couldn’t find any set of instructions this clear and this precise. This has been cobbled up from many sources and modified by me to fit our scenario. But, I believe this should be useful for anyone compiling OpenSSL for Visual Studio from 2003 and beyond.

Basically, there are two ways to do this: With the Visual Studio assembler or with the Netwide Assembler. I will explain them in tandem. After some (read: many) iterations on this, I’m not sure if there is a problem with either or which one is better. I ended up using the Netwide Assembler. It, however, requires another install. So my suggestion is using the VS assembler and if you have problems you can’t fix, try the Netwide Assembler.

Ingredients:

  • Install the Perl compiler for windows. Put it in an easy to reach place like C:\Perl
  • Download the latest OpenSSL sources. Put them in an easy to reach place like C:\openssl-<version>
  • If you are using the Netwide Assembler (NASM), install that too. Put it in an easy to reach place like C:\NASM

For x86 libraries:

  1. Open Visual Studio x86 Command Prompt (Should be in your Visual Studio tools subdirectory)
  2. Change dir to the OpenSSL folder.
  3. “perl Configure VC-WIN32 no-shared no-idea” (watch the capitals)
  4. “ms\do_ms.bat” (For NASM it’s “ms\do_nasm.bat”)
  5. Edit ms\nt.mak file: add “/SAFESEH” to LFLAGS (also, watch the capitals)
  6. For NASM, Edit ms\nt.mak file: change line 52 to set “C:\NASM\nasm.exe” as the assembly command
  7. “nmake -f ms\nt.mak”
  8. This will take a few minutes but in the end you will have two important directories: inc32 and out32. In out32 you will find your two static libraries “libeay32.lib” and “ssleay32.lib”. Put them in a lib directory your linker can use. In inc32 are the headers. Copy all of them into an include directory your compiler can use.

For x64 libraries:

  1. Open Visual Studio x64 Command Prompt (Should be in your Visual Studio tools subdirectory)
  2. Change dir to the OpenSSL folder.
  3. “perl Configure VC-WIN64A no-shared no-idea”
  4. “ms\do_win64a”
  5. Edit ms\nt.mak file: add “/SAFESEH” to LFLAGS
  6. Edit ms\nt.mak file: change directories (lines 37-42) to be 64 and not 32
  7. For NASM, Edit ms\nt.mak file: change line 52 to set “C:\NASM\nasm.exe” as the assembly command
  8. “nmake -f ms\nt.mak”
  9. Same as above only this time the directories are inc64 and out64 (if you changed the directories accordingly in step 6)

Thanks to everyone who helped and/or unknowingly contributed to this guide. If there are problems with it, I happily accept corrections and suggestions.


Posted in Programming by with 4 comments.

Comments