OpenSSL installation and configuration tutorial under Windows

  

Recently used openssl, never used before, so I feel very strange, from downloading and installing, to compiling, intermittently engaged in two days, online articles about openssl are also many, But it may be difficult to find a problem that can completely solve your problem, and finally it is finally patched up. So hurry up and sort out, maybe the latecomers will realize the point. The openssl official website documentation is also very comprehensive... In case of special problems, please take a look at the official website FAQ and the install.w32 (install.w64) file in the openssl directory (directly to the browser).

This article system environment: Windows
XP SP2+Visual Studio 2005+Perl 5.8.6+OpenSSL 0.9.8.

First, pre-installation preparation

1, install Visual Studio 2005

If you install VC++60, you will always lack some when compiling OpenSSL. Files, such as ml.exe, cl.exe.... and masm errors, etc., the head is big, still waiting to test, no time to try a little, directly into Visual Studio 2005.

2, install Perl

Download: http://www.activestate.com/ActivePerl

Tianyuan installed ActivePerl-5.8.6.811-MSWin32-x86- 122208.msi version, too high version is useless, used to do mobile phone software has always been interested in this version. The default installation directory is C:\\Perl.

3, download OpenSSL 0.9.8

Download address: http://www.openssl.org/source/, the version should not be too new (if it is to do product development recommendations with the latest, All the software in the early stage test can be used older, and there will be less compatibility problems. The new version tends to have a larger span and more modifications. It is naturally easy to fight when multiple softwares are combined.

If you just use OPENSSL, and the version is appropriate, you can try to compile it, download and install it directly:

http://www.openssl.org/related/binaries.html

Second, install OpenSSL

1, unzip OpenSSL to the system disk

such as C:\\OpenSSL.

2. Configure WIN32 environment

Open the CMD command line and enter the C:\\OpenSSL directory. Execute the command

perl Configure VC-WIN32

3. Go to the VC BIN directory, configure the VC environment variable

to enter the VS installation path VC/Bin directory, run:

VCVARS32.BAT

Set environment variables.

4, return OpenSSL directory, create makefile

ms\\do_ms

This command does not perform assembly language compilation, such as the end of the report error, you can try ms\\do_masm (use Assembly language), ms\\do_nasm, ms\\do_nt, etc. These configuration files are batches written for different system configurations.

As for the difference between these commands, the other ones are not used for the time being, and those with experience are welcome to enlighten me.

- If you are using MASM then run:

> ms\\do_masm

- If you are using NASM then run:

> ms \\do_nasm

- If you don't want to use the assembly language files at all then run:

> ms\\do_ms

5, in the Openssl directory, Execute compilation

nmake -f ms\ tdll.mak

When the compiled dynamic library is finished, the output is in the out32dll directory: including the executable file, two dlls and two lib files: Libeay32.dll, libeay32.lib, ssleay32.dll, ssleay32.lib, if you use VS/VC programming, just follow the method below. If you need to use the openssl command, you need to add c:\\ to the system environment variable path. Openssl\\out32dll path, because openssl.exe is in this directory, you can use the openssl command directly on the command line after declaration.

Three, programming settings

1, configuration include file

Open VS->Tools->Options->projects and solutions->VC++ Directories(VC6 Path VC->Tools->Options->Directories), add C:\\openssl\\inc32 directory in Include files, assuming that the openssl installation directory is C:\\openssl, the same below.

Add C:\\openssl\\out32dll to Libray files.

2. Include header files, import LIB library

Include the following three header files in the source program and add them to LIB:

#include <openssl/ssl.h> #include <openssl/err.h>#include <openssl/bio.h>#pragma comment(lib, "libeay32.lib")

#pragma comment(lib, "ssleay32.lib" ;)

3, more OpenSSL programming reference:

four, common mistakes and solutions

1, do not know NMAKE?

Workaround A: http://www.question-defense.com/2009/03/27/nmake-is-not-recognized-as-an-internal-or-external-command-operable- Program-or-batch-file

Workaround B: Use the VS2005 console, Start Menu->Microsoft Visual Studio 2005->Visual Studio Tools->Visual Studio 2005 Command Prompt. The NMAKE directory is actually under C:\\Program Files\\Microsoft Visual Studio 8\\VC\\bin.

2, NMAKE compile fatal error?

NMAKE : fatal error U1077: 'cl' : return code '0x2'

NMAKE : fatal error U1077: 'ml' : return code '0x1'

NMAKE : Fatal error U1077: 'link' : return code '0x460'

If you encounter the above error, please refer to: http://www.flatws.cn/article/program/perl/2011-05-19/26439 .html

3, NMAKE compilation encountered message Error?

If encountered:

Message: 'The POSIX name for this item is deprecated. Instead, use the ISO C++ conformant name: _read. See online help for details.' NMAKE : fatal error U1077: '"C:\\Program Files\\Microsoft Visual Studio 8\\VC\\BIN\\cl.EXE"' : return code '0x2'

Stop.

Error, open ms\ tdll.mak and remove the /WX flag from CFLAG= /MD /W3 /WX.....

4, _md5_block_asm_host_order compilation error?

If the following error occurs, try compiling the command using ms\\do_masm.

link /nologo /subsystem:console /machine:I386 /opt:ref /dll /out:out32 dll\\libeay32.dll /def:ms/LIBEAY32.def @C:\\DOCUME~1\\Test\\ LOCALS~1\\Temp\ m58C.tmp ms/LIBEAY32.def(7) : warning LNK4017: DESCRIPTION statement not supported for the target platform; ignoredCreating library out32dll\\libeay32.lib and object out32dll\\libeay32.expmd5_dgst.obj : error LNK2019: Unresolved external symbol _md5_block_asm_host_order referenced in function _MD5_Updateout32dll\\libeay32.dll : fatal error LNK1120: 1 unresolved externalsNMAKE : fatal error U1077: '"C:\\Program Files\\Microsoft Visual Studio 8\\VC\\BIN\\link.EXE"' : return Code '0x460'Stop.

Copyright © Windows knowledge All Rights Reserved