34

I want to build OpenSSL in Windows with MinGW,
How can I do that? Please help me.
Thanks.

Aykhan Hagverdili
  • 28,141
  • 6
  • 41
  • 93
Harry Fox
  • 603
  • 2
  • 6
  • 11

1 Answers1

57

This is an extract from a personal how-to I wrote. It has since been transformed to a script (look at the OpenSSL section, obviously). It assumes you have a working installation of MinGW and that you have a working MSys console.


OpenSSL

To build OpenSSL, you need a working Perl installation.

Download OpenSSL from its official website and decompress the archive.

Windows 32/64 bits - MinGW

You must run these commands from a MSys console.

For 32 bits:

perl Configure mingw no-shared no-asm --prefix=/c/OpenSSL

For 64 bits:

perl Configure mingw64 no-shared no-asm --prefix=/C/OpenSSL-x64

Then:

make depend

make

make install

The make depend line is only needed on the most recent OpenSSL version if you specified any of the no-... options.

Note that this will compile OpenSSL in static mode.

If at some point you get a "make (e=2):" error, ensure you don't have another "make.exe" in your PATH or just type /bin/make instead of make.


You may, of course, need to compile it with other options (such as dynamic linking, or asm enabled). So feel free to look at the help perl Configure can provide to know more about the available options.

Machavity
  • 30,841
  • 27
  • 92
  • 100
ereOn
  • 53,676
  • 39
  • 161
  • 238
  • Thanks for your help. i accomplish your instruction and build OpenSSL, but it doesn't make DLL files? where is it? – Harry Fox Feb 21 '12 at 15:22
  • @HarryFox: You may have noticed the `no-shared` parameter which explicitely disables shared library generation. Since on Windows, shared libraries are DLL you have your answer :) Now I never had to build OpenSSL's DLLs but I guess replacing `no-shared` with `shared` might do the trick. – ereOn Feb 21 '12 at 15:24
  • From my [very limited] experience, Strawberry Perl (5.14.2.1 for x64) hangs in MSYS. ActivePerl worked great. – Elliot Cameron Jun 14 '12 at 20:46
  • 2
    For more recent versions of openssl, you'll need to run `make depend` before running `make` if you're passing any of the `no-xyz` flags to `Configure`. – Elliot Cameron Jun 14 '12 at 21:24
  • @3noch: Thanks. I updated both the answer and the original how-to. – ereOn Jun 15 '12 at 06:55
  • @ereOn: I believe you need `make depend` *before* `make`... thanks for updating! – Elliot Cameron Jun 15 '12 at 13:44
  • Are the static outputs still named `libcrypto.a` and `libssl.a` or am I doing something wrong? (I would expect a `.lib` extension.) – Elliot Cameron Jun 15 '12 at 13:47
  • @3noch: I get `.a` files too. Which is what one would expect to use with MinGW. What did you expect ? – ereOn Jun 15 '12 at 17:15
  • @ereOn: I was under the impression that building with MSYS somehow generated native Windows binaries (e.g. `.lib` files that could be linked in to any Windows project outside of MSYS). I must be wrong? – Elliot Cameron Jun 15 '12 at 18:16
  • 4
    @3noch: There is no such thing as a "native Windows binary format" for libraries. You can generate libraries that are usable by a specific compiler toolchain. On Windows that can be `cl.exe` (Microsoft) or `gcc.exe` (MinGW). Now for C libraries, sometimes the resulting library can be used by both compiler because they use similar function decoration mechanism. If you want to build OpenSSL for Visual Studio, read the link I gave, as it contains the appropriate instructions as well ;) – ereOn Jun 15 '12 at 23:16
  • I know "thanks" are typically discouraged, but working with OpenSSL has been a real pain in the arse-- I have no idea why this dependency has to be so difficult to work with. Your guide has been book marked and should be referenced on all INSTALL pages. This worked fast and perfectly. – RLH Oct 23 '13 at 12:40
  • @RLH: Thanks for the kind words. I had to struggle a lot with it myself. Glad my guide can make other people's life easier. – ereOn Oct 23 '13 at 13:02
  • superb, I was struggling to build openssl since 5 days. you came to rescue me. – Raiden Core Jul 24 '16 at 11:06
  • I did make test, all test pass. you may want to add this as a final step to the recipe you made. – Raiden Core Jul 24 '16 at 11:21
  • When I run any of the make commands in msys I get "/bin/sh: /user/bin/perl: No such file or directory" even though I just used perl to configure. – Braden Steffaniak Jan 09 '17 at 10:02
  • @BradenSteffaniak Don't use the perl that comes with msys, use ActivePerl (that you must install and reference **explicitely**). It won't work otherwise. – ereOn Jan 09 '17 at 20:31