Building LuaSec/LuaCrypto/OpenSSL for Lua on Windows

OpenSSL and LuaSec/LuaCrypto are pretty common libraries within the Lua eco system. Where other cornerstone libraries are on their own (LuaSocket and LuaFileSystem/lfs), the issue with LuaSec/LuaCrypto is that they are bindings to OpenSSL, which requires a properly compiled OpenSSL version. (“properly compiled” is related to the runtime libraries used, they need to be compiled against the same versions, so just grabbing the OpenSSL dll files from some other project might deliver unexpected results/failures/crashes)

This post assumes: Using the GCC compiler with MinGW, and building 32 bit versions.


Compiling OpenSSL

Download the OpenSSL source from  and unpack it in “c:\temp\openssl\”.

Two issues needed to be fixed in my case;

  • I had to add ‘perl’ to my MinGW setup (see this post on how to setup MinGW for use with Lua on Windows). Just open the GUI (in my case in “C:\MinGW\libexec\mingw-get\guimain.exe”), under “all packages / MSYS / MinGW Developer Toolkit” select all the “msys-perl” packages, and select “Apply changes” from the “Installation” menu.
  • With older openssl versions 3 files gave me errors, due to failed symlinks from the unpacked archive. Update the following files in “c:\temp\openssl\test\”;  rc5test.c, md2test.c, jpaketest.c and change the line ‘dummytest.c’ to ‘#include “dummytest.c” ‘. (source of the resolution). Version 1.0.2f did not give me those errors anymore.

Start MSYS (comes with MinGW, in my case in “C:\MinGW\MSYS\1.0\msys.bat”). And execute the following;

cd /c/temp/openssl
./configure mingw shared
make test

This should build and test OpenSSL (takes a few minutes). Now add the OpenSSL libraries to the Lua config (next to lua.exe), using the file explorer, or type the following (with adjusted paths) into a commandshell;

copy "c:\temp\openssl\apps\*eay32.dll" "c:\program files (x86)\Lua\5.1\bin"


Building the LuaSec and LuaCrypto bindings

Let LuaRocks build and install the LuaSec binding between Lua and OpenSSL, by doing from a commandshell;

luarocks install luasec OPENSSL_INCDIR=/temp/openssl/include/ OPENSSL_LIBDIR=/temp/openssl/ OPENSSL_BINDIR=/temp/openssl/apps/

NOTE: At the time of writing the official published rockspec would not work, so instead of the `install luasec` part in the LuaRocks command I had to use the full path to the rockspec on github; `install`.

For LuaCrypto we can use a similar command, just replace `luasec` with `luacrypto`;

luarocks install luacrypto OPENSSL_INCDIR=/temp/openssl/include/ OPENSSL_LIBDIR=/temp/openssl/ OPENSSL_BINDIR=/temp/openssl/apps/

That’s all there is to it!

3 thoughts on “Building LuaSec/LuaCrypto/OpenSSL for Lua on Windows

  1. Hello and thank you for the detailed guide.

    Iam running into some problems when trying to do the luarocks install for luacrypto bind

    More specifically when I try to do

    luarocks install luacrypto OPENSSL_INCDIR=/temp/openssl/include/ OPENSSL_LIBDIR=/temp/openssl/ OPENSSL_BINDIR=/temp/openssl/apps/

    I get

    c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -llibssl32MD
    c:/mingw/bin/../lib/gcc/mingw32/6.3.0/../../../../mingw32/bin/ld.exe: cannot find -llibcrypto32MD

    – I followed your other guide ( to install MinGw LUA and Luarocks with no problems
    – I have LUA 5.1 , MinGW (latest update ), Luarocks 2.4.4, openssl-1.0.2o
    – I fully compiled Open SSL 1.0.2o with no problems (make, make test were OK)

    Can you please help?

    Thank you

    • Unfortunately it doesn’t work like that. Most platforms use source distributions, where Windows uses binary distributions. This means that you need to match the Lua engine and the libraries you use with the same underlying dll’s (the C runtime libraries). If they do not match you’ll get weird and hard to track down errors/failures. So your safest bet is to compile them yourself, though I realise that for most Windows users this does not come naturally.

Leave a Reply

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


This site uses Akismet to reduce spam. Learn how your comment data is processed.

Subscribe without commenting