Home > Programming > OpenSSL Compilation on Win32

OpenSSL Compilation on Win32

July 7, 2007

Following on from my "Common problems compiling my code" blog entry, another popular email question I get is related to my SMTP class is problems related to getting OpenSSL support compiled into the class. Here’s a snippet from the OpenSSLMfc.h header file which provides a simple encapsulation of a socket connection using OpenSSL:

#include <openssl\ssl.h> //If you get a compilation error about this missing header file, then you need to download OpenSSL from http://www.openssl.org and build a Win32 version and incorporate it into Visual C
#include <openssl\err.h> //If you get a compilation error about this missing header file, then you need to download OpenSSL from http://www.openssl.org and build a Win32 version and incorporate it into Visual C
#include "SocMFC.h"

As you can see it references the OpenSSL header files "ssl.h" and "err.h". You can download OpenSSL directly as the code comments mention above from http://www.openssl.org. As of 7th of July 2007, the latest version of OpenSSL is 0.9.8e. Once you have downloaded OpenSSL you should read and follow the build instructions in the file INSTALL.W32 included in the OpenSSL download. Basically the steps are:

  1. You will need to have Perl for Win32 installed. If you do not have it you can download ActiveState Perl from http://www.activestate.com/ActivePerl
  2. Bring up a Visual Studio command prompt, navigate to the OpenSSL install directory (say c:\some\openssl) and run Configure as follows:
    perl Configure VC-WIN32 –prefix=c:/some/openssl/dir
    This assumes that you have setup perl to be in your search path
  3. Assuming you do not want to mess about with assembly language, type ms\do_ms from your command prompt. Examine the window for any errors.
  4. Then type nmake -f ms\ntdll.mak which will actually perform the compile and link of the OpenSSL code. This may take a while. When it finishes examine the out32dll directory which should contain the OpenSSL DLLs and executables. Note that by default this will only produce "release" mode binaries and you need to manually edit and rerun the make process if you want to create "debug" binaries. Also to avoid the "debug" binaries overwritting the already created "release" binaries, you need to edit the make file or backup the existing binary files. Basically this step is a bit of a mess to get right!
  5. Point your copy of VC to the appropriate Include and Lib directories. In our example this would be "c:\some\openssl\inc32" and "c:\some\openssl\out32dll" respectively. If you are using Visual Studio 2005, this would be using the menu item "Tools -> Options -> Projects and Solutions -> VC++ Directories -> "Include Files" & "Library Files"
  6. Update your project linker settings to link to the correct OpenSSL libraries. This will normally be ssleay32.lib libeay32.lib for release mode builds.

If all of the steps above prove to be too much work, then a company called Shining Light Productions have very kindly packaged up the end results of all this work into a nice and simple installation package for us Windows developers.

  1. You can download the Win32 OpenSSL Installation Project from http://www.slproweb.com/products/Win32OpenSSL.html. As of 7th of July 2007, you can download either OpenSSL v0.9.8e and v0.9.7m. Both of these are the most recent builds from each stream of OpenSSL. When you install the download on your machine, you end up with the static import libraries in a "Lib\VC\static" directory below the install directory, the DLL import libraries in a "Lib\VC" directory and the main include files in a "include" directory (again both below the install directory). The download a new developer to OpenSSL should select is the "Win32 OpenSSL v0.9.8e download" link.
  2. To complete the integration with VC, setup the Include and Lib directories as in Step 5 above. Assuming you installed the Win32 OpenSSL project into C:\dev\openssl-0.9.8e, you would add "c:\dev\openssl-0.9.8e\include" to the Include setting and "C:\dev\openssl-0.9.8e\lib" to the Lib setting in VC.
  3. You need to link to the correct import library depending on how you build your code. 8 different DLL import lib files are provided in the Lib\VC directory and a further 8 in the Lib\VC\Static directory. The 2 OpenSSL libraries namely libeay and ssleay each come in 4 varieties with the Win32 OpenSSL Project, resulting in 8 DLL import libraries and 8 static import libraries. These are:

    libeay32MD.lib
    libeay32MDd.lib
    libeay32MT.lib
    libeay32MTd.lib
    ssleay32MD.lib
    ssleay32MDd.lib
    ssleay32MT.lib
    ssleay32MTd.lib

    Which ones you use depend on how you are building your client project and its use of the VC runtime. For more information see http://msdn2.microsoft.com/en-us/library/2kzt1wy3(VS.80).aspx. The differences basically correspond to whether you want to use the VC runtime DLL or statically embed the VC runtime in your application.

Hopefully this info will help you get up and running with OpenSSL and my SSL classes in your own code.

Happy coding!

Advertisements
Categories: Programming
  1. Unknown
    May 15, 2009 at 11:43 am

    Hi,Great blog with interesting informations. I can use it t solve my problem.ThanxM.http://www.vanjobb.hu/

  2. Andy
    November 9, 2009 at 9:12 pm

    I had to modify "opensslconf.h" after the perl configuration. It captured my paths in the form of "c:\\…\\…" etc. The compiler thought that I was trying to feed it escape sequences. I changed it to "c:\\\\…\\\\…" and then built using the makefile.

  3. March 9, 2011 at 11:58 pm

    Hi PJ,

    Thanks for all your wonderful work 🙂 you are a great example to us all.

    Given all the extra steps invloved in getting SSL compiling, do you have any plans to support updated versions of your SMTP API without SSL – or produce instrustions as to how to strip out SSL for projects that dont need it?

    Best regards,

    Neil

  4. March 10, 2011 at 12:47 am

    Hi PJ,

    Just spotted this…

    If you do not want to include SSL support in CPJNSMTPConnection, then you should define the pre-processor macro “CPJNSMTP_NOSSL” before including PJNSMTP.h. In this case, you do not need to include the OpenSSLMfc.cpp/h modules in your project

    Thanks again,

    Neil

    • March 10, 2011 at 1:41 am

      Following up on the Neil’s comments about excluding SSL support from my CPJNSMTPConnection class, this feature of the class is documented in usage section in the html documentation included in the download. A case of RTFM perhaps.

  5. August 24, 2014 at 3:05 pm

    I’m often to blоgging and i truly respect your content.

    The information has actually peaks my interest.
    I am going to bookmark your site and keep cҺecking forr brand spanking new
    information.

  1. August 24, 2014 at 4:55 pm
Comments are closed.
%d bloggers like this: