Building OpenSSL with MinGW on Windows

A number of libraries applications depend on OpenSSL, to name a few: cURL, QtNetwork, WebKit, your IMAP or secure SMTP client, etc. Building of OpenSSL is painstaking, unless you know some tricks. Read more for guidance.

  1. If you yet to have MinGW, read to learn how to install it.
  2. Download Perl from ActiveState site: . Choose version that match your Windows. MSI installer is recommended, unless you are so fluent in Windows and don’t mind spending time with little tweaks like adding PATH, etc
  3. Run the MSI installer and point path to C:\develop\tools\perl . You may choose different path, but that’s what on my machine.
  4. Having installed with Perl, now let’s fetch OpenSSL: (the latest version of OpenSSL 0.9.8 at the time of writing).  I wouldn’t recommend chasing after the version 1.0 for now.
  5. Extract openssl to C:\develop\tools\ and you will obtain directory C:\develop\tools\openssl-0.9.8n . Get inside it.
  6. Before you start building anything, take note that the macro OPENSSL_IMPLEMENT_GLOBAL causes fatal errors. Find it inside the files openssl-0.9.8n\e_os2.h , openssl-0.9.8n\include\openssl\e_os2.h and openssl-0.9.8n\outinc\openssl\e_os2.h . Find the macro’s definition and change

static type _hide_##name


/* static type _hide_##name */ type _hide_##name

  1. Now let’s build shared & static versions of OpenSSL with a single command (you are now inside C:\develop\tools\openssl-0.9.8n):

ms\mingw32.bat shared

Navigate to YouTube and have some snack. It may take 15-20 mins to finish building.

  1. When building is finished, you can copy outinc\openssl to your mingw\include directory. You also can copy generated *.a and *.dll files to mingw\lib directory and the *.dll to mingw\bin directory. If you hate copying, remember to make use of -I and -L flags to appropriate folders when building with MinGW.

Building & installation of OpenSSL is done.

Edit: As noted by Darrell Walisser in the comments part, Perl distributed with msys was the culprit. Installing ActiveState Perl will solve the issue without this workaround. Thanks Darrell!



5 thoughts on “Building OpenSSL with MinGW on Windows”

  1. Hi,

    After the compilation, I do we include the OpenSSL library in the C scripts – using MinGW? For example the header file bn.h?
    There’s also a version for windows 32 of OpenSSL; can we use it instead?
    But how do we call the header files? Where do we place the library?

    Kind regards,

    Rui Fernandes

  2. I got an error during the build

    Building OpenSSL
    copy “.\\e_os.h” “tmp\e_os.h”
    /usr/bin/sh: copy: command not found
    mingw32-make: *** [tmp\e_os.h] Error 127

    I think the error is in the generated mingw32a.mak
    . . . .
    $(RM) $(TMP_D)\*.*
    $(RM) $(OUT_D)\*.*

    $(INCL_D)\e_os.h: $(SRC_D)\\e_os.h
    $(CP) “$(SRC_D)\\e_os.h” “$(INCL_D)\e_os.h”

    $(INCL_D)\cryptlib.h: $(SRC_D)\\cryptlib.h
    $(CP) “$(SRC_D)\\cryptlib.h” “$(INCL_D)\cryptlib.h”

    the copy command is wrong generated
    it should consist of 3 items separated by space
    but is generated into mingw32a.mak as
    $(CP) “$(SRC_D)\\e_os.h” “$(INCL_D)\e_os.h”
    resulting in
    copy “.\\e_os.h” “tmp\e_os.h”
    which is wrong


  3. It should be noted that the msys perl interpreter (/bin/perl.exe) will create the wrong copy command as noted above. ActiveState perl will solve the issue.

Leave a Reply

Your email address will not be published. Required fields are marked *