posts - 11,  comments - 0,  trackbacks - 0
Original link: http://naughter.spaces.live.com/Blog/cns!7692E6D72E26EAC!209.entry

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 fromhttp://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 seehttp://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!

posted on 2010-04-30 17:03 SearchDream 阅读(869) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理


<2024年12月>
24252627282930
1234567
891011121314
15161718192021
22232425262728
2930311234

常用链接

留言簿

随笔档案

搜索

  •  

最新评论

阅读排行榜

评论排行榜