The present post is a recipe for building static and dynamic OpenSSL libraries for all versions of OpenSSL on the Windows platform, viz. mingw using the gnu c++ compiler. In another posts we treat the msvc (Microsoft Visual Studio C++ compiler) toolchain. Any mingw toolchain could be used for the present purpose. However, there are quite a number of mingw distributions around that differ in a not well-documented way. As in our company we build multi-platform (Windows, Mac and Linux) applications using the Qt IDE we will use the mingw distribution (version 492-32bit) that comes with the open source Qt package (version 5.5.1 at present). Our goal is to have in the end the following 2 static libraries:
The following 2 import libraries
And the following 2 dynamic libraries:
Quick editing of the PATH environment variable
You will have to run several applications from the command line to compile OpenSSL. For your convenience it is advisable to have the location of these applications in your PATH environment. In earlier days one had to restart Windows to have a change in the SYSTEM environment to become active. This awkward situation has changed now. We use the free gui utility Rapid Environment Editor with which you can edit the SYSTEM and USER environment variables in such a way that these changes become immediately active if you open a *new* instance of explorer or a *new* instance of the MS-DOS terminal window (cmd.exe). Sometimes Windows caches the environment variables in such a way that a new change will not become active. This unwanted situation could occur for instance after installing a new program that adds its own file location to the PATH environment. To force to refresh the cache just edit the PATH variable and save and then undo the previous edit and save again. Now the most actual PATH will be known to all applications that need the environment for their execution.
All the following requirements are essential. Do not go to a next requirement if you have not fulfilled the previous requirement.
You will need the perl program. Open an MS-DOS command window and runperl -v
If you get something like:'perl' is not recognized as an internal or external command ...
you do not have perl installed. We advise to use the free ActiveState perl distribution. Then running the previous command should give something like:This is perl 5, version 20, subversion 2 (v5.20.2) built for MSWin32-x64-multi-thread (with 1 registered patch, see perl -V for more detail) Copyright 1987-2015, Larry Wall Binary build 2002  provided by ActiveState http://www.ActiveState.com
You are OK now.
I assume you have somewhere a mingw distribution whose gcc compiler you want to use. Open an MS-DOS cmd window at the file location of this gcc compiler of the mingw32 distribution and rungcc -v
The last line of the response should be something likegcc version 4.8.0 (rev2, Built by MinGW-builds project) ..
Open another MS-DOS window at root c:\ and run againgcc -v
If the response is exactly the same as you had before you have the right mingw toolchain and it is also in your PATH. If you get another response you have to add the mingw location to your PATH and/or you have to remove from your PATH the location containing other gcc compilers.
- GNU make
You will need the GNU make utility and it must be in your PATH. On a Windows development computer there are usually a number of programs called "make", and worse some of them are in your PATH. Open a MS-DOS window at root location and runmake -v
The response should be something likeGNU Make 3.81 ...
Any other response, like a Microsoft "make" is wrong. Get these other "make"'s out of the PATH (possibly only temporarily). If you still do not get the GNU response you will have to install GNU make. Download it from the internet (it is shipped with MSYS).
The OpenSSL source comes as a compressed (gz) archive (tar) which in the Linux world is called a tarball. The OpenSSL archive (may) contain file links. Although Windows supports some form of file links their implementation is not compatible with Linux-type links. As a result the popular zip/unzip Windows utilities can produce incomplete uncompressed archives if there are file links in the archive. For this purpose we strongly advise to use the GNU "tar" utility to untar the tarball. The tar utility ships with the above mentioned MSYS distribution. So open an MS-DOS terminal at root and runtar --version
The response should be something like:tar (GNU tar) 1.23Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.Written by John Gilmore and Jay Fenlason.
Dynamic link libraries
We will now compile for the case of generating dynamic link libraries.
- Download the required OpenSSL version. It is a compressed file (tarball tar.gz. ) Untar the tarball with tar. Open a MS-DOS terminal window at the location of the tarball and run
tar -xf vv.tar.gz
where vv is the OpenSSL version (like 1.0.2e). Neglect the warnings about file links. Check that the tarball is indeed decompressed in its own new directory.
- Open an MS-DOS cmd window at the root location of the OpenSSL source distribution. That directory should have a file called "Configure". Run
perl Configure mingw shared
it should do some stuff ( a minute or so) and should end with something likeConfigured for mingw
- Run in the same terminal
The terminal window should start compiling and after some time (10 minutes in our case) it should end with no errors.
- The two dll's and the two import libraries mentioned in the beginning of this post can be found at the root of the source directory. You can move them to a suitable location. You probably also need the include/openssl directory. Please check that the files in this directory are real files and not file links. If they are file links copy them using a MS-DOS window with "copy", as this will automatically replace the links with the real files.
If you want to generate static libraries the procedure is almost identical to the one described for the case of dynamic libraries. Just replace
You now can collect the two static libraries and the include branch.