Marc Wäckerlin
Für eine libertäre Schweiz

Cross Compile OpenSSL for Windows on Linux

May 7, 2014

This article explains how to configure and build the OpenSSL library on a Ubuntu Linux to run on 32bit or 64bit Windows. After you have set up your cross compile environment as described in my previous article, you are now ready to start compiling for example OpenSSL, which is a requirement for Qt5 that will be described in my next article.

To cross compile OpenSSL for Windows on an Ubuntu Linux using MinGW, you need to perform the following steps:

  1. Find and download the latest sources from
  2. Unpack the file and change to that directory
  3. Chose your OpenSSL target name, which is different from the MinGW target name and is mingw for 32bit i686-w64-mingw32 and mingw64 for 64bit x86_64-w64-mingw32
  4. To configure for 32bit Windows, call ./Configure mingw shared --cross-compile-prefix=i686-w64-mingw32-
    Note: Without the addition shared, the required runtime DLLs are not built
  5. Run make and optionally make install (i.e. if you have added a --prefix=/install/path option to Configure)
  6. Note: The runtime DLLs are not installed to the installation path, you find them in your local path, try ls *.dll after your build
  7. There is a bug in OpenSSL that must be fixed manually: In the include file openssl/x509v3.h add just after line #define HEADER_X509V3_H on the top the following lines:
    #ifdef X509_NAME
    #undef X509_NAME

It is possible to do everything fully automated, e.g. in a Jenkins build script:


file=$(wget -qO- $source | sed -n 's,.*<a *href="\(openssl-[0-9][^"]*\.tar\.gz\)".*,\1,p'  | head -1)
wget -qO$file $source/$file
tar xf $file
cd $path

case ${MINGW} in
    (*) false;;

./Configure ${TARGET} shared --cross-compile-prefix=${MINGW}- --prefix=${WORKSPACE}/usr

make install
cp *.dll ${WORKSPACE}/usr/lib/

zip -r ${path}~windows.${BUILD_NUMBER}_${ARCH}.zip usr

Build MinGW Targets in Docker

I support a maintained docker image that contains an Ubuntu based build environment and build scripts for several libraries and programs. This is i.e. QT and all it’s dependencies, and my own projects with all their dependencies:

List all available build scripts:

docker run -it –rm mwaeckerlin/mingw -c ‘ls /build-*.sh’

Show options for building OpenSSL:

docker run -it --rm mwaeckerlin/mingw / -h

Compile latest OpenSSL in the current working directory:

docker run -it --rm -v $(pwd):/workdir -u $(id -u) mwaeckerlin/mingw / -d

Build ICU version 57-1 in the current working directory:

docker run -it --rm -v $(pwd):/workdir -u $(id -u) mwaeckerlin/mingw / -d -v 57-1

Just Download Built Archives

You can download already built images for 32bit and 64bit on my repository:


[…] hacks have gone, cross-compilation is very simple. This is my first example of a 3rd-party library. Next article will talk about cross compiling […]

What’s the purpose of editing those two lines?

You mean the «undef»? This macro is defined in more than one files. At the second definition, the compiler complains. So I first undefine it, then it can be redefined later in the file.

Editing the two lines is no more necessary.

Thank you for your efforts on this. I am facing an issue while trying to cross compile openssl-fips for windows on linux. What I have done is I have added the flag fips in ./Configure but while executing the file it gives the following stack trace error:

-DFINGERPRINT_PREMAIN_DSO_LOAD -o fips_premain_dso.exe \
/usr/local/ssl/fips-2.0/lib/fips_premain.c /usr/local/ssl/fips-2.0/lib/fipscanister.o \
libcrypto.a -lws2_32 -lgdi32 -lcrypt32
/usr/local/ssl/fips-2.0/lib/fipscanister.o: In function `FIPS_module_mode’:
(.text+0×143): undefined reference to `__stack_chk_fail’
/usr/local/ssl/fips-2.0/lib/fipscanister.o: In function `FIPS_selftest_failed’:
(.text+0x25a): undefined reference to `__stack_chk_fail’
/usr/local/ssl/fips-2.0/lib/fipscanister.o: In function `FIPS_incore_fingerprint’:
(.text+0×447): undefined reference to `__stack_chk_fail’
/usr/local/ssl/fips-2.0/lib/fipscanister.o: In function `FIPS_check_incore_fingerprint’:
(.text+0x5ef): undefined reference to `__stack_chk_fail’
…. and the stack trace goes on.

Do you have any pointers as to how to resolve this issue. Please let me know if you can provide any help. I will be grateful.

Also I have already installed openssl fips in the docker container.

Hi Naveed Jamil

Perhaps this could help: