MRW
http://piratenpartei.ch

Piratenpartei Zürich
PC 85-112704-0

Der Politnetz Auftritt von Marc Wäckerlin Im Politnetz unterstützen

OpenSSL für Windows/MinGW unter Linux CrossCompilieren

Better Solution: Create the DLLs

OpenSSL 1.0.0d

Apply patch openssl-1.0.0d-configure.patch to file Configure in openssl-1.0.0d, then call config with apropriate cross-compile options and call make and make install:

cd openssl-1.0.0d
patch -p1 < openssl-1.0.0d-configure.patch
./config --cross-compile-prefix=i586-mingw32msvc- --prefix=/opt/local/i586-mingw32msvc shared mingw
make
sudo make install

Details of the Patch

Remove "die"-Line

Without the patch, you first drop into the error message:

> ./config --cross-compile-prefix=i586-mingw32msvc- --prefix=/tmp/openssl shared mingw
Operating system: x86_64-whatever-linux2
Configuring for linux-x86_64
target already defined - linux-x86_64 (offending arg: mingw)

That's why the die-line is commented out.

Change Link Arguments

According to http://wagner.pp.ru/~vitus/articles/openssl-mingw.html, symbols are not exported by default, that's why there is need for adding -Wl,–export-all -shared.

Just get a build environment for Linux (without applications nor DLLs)

OpenSSL 1.0.0c, 1.0.0d

  1. ./config --cross-compile-prefix=i586-mingw32msvc- --prefix=/opt/local/i586-mingw32msvc mingw:gcc
  2. Edit Makefile, search line DIRS=, remove the following directrories: apps test tools
  3. make
  4. sudo make install

OpenSSL 1.0.0a

For OpenSSL Version 1.0.0a, it's quite better now:

  1. ./config --cross-compile-prefix=i586-mingw32msvc- --prefix=/opt/local/i586-mingw32msvc mingw:gcc
  2. edit file engines/e_capi.c and add below #include <wincrypt.h> (line 73):
    /* additional definitions required for e_capi.c  */
     
    typedef struct _PUBKEY {
         DWORD magic ;
         DWORD bitlen ;
    } DSSPUBKEY ;
    #define CERT_STORE_PROV_SYSTEM_A            ((LPCSTR) 9)
    #define CERT_STORE_READONLY_FLAG                        0x00008000
  3. make && make install
  4. → linking fails!

See also: http://www.mail-archive.com/openssl-users@openssl.org/msg60703.html

OpenSSL 0.9.8k

With older OpenSSL Version 0.9.8k:

  1. Edit Configure, remove or comment out line: $IsMK1MF=1 if ($target eq "mingw" && $^O ne "cygwin" && !is_msys());
  2. ./config --prefix=/opt/local/i586-mingw32msvc mingw:i586-mingw32msvc-gcc
  3. Edit Makefile, search line DIRS=, remove the following directrories: apps test tools
  4. Correct all ar commands: perl -pi -e 's#=ar #=i586-mingw32msvc-ar #g' $(find -name Makefile)
  5. make
  6. sudo make install

Reason:

  1. Remove $IsMK1MF=1 if ($target eq "mingw" && $^O ne "cygwin" && !is_msys()); from Configure because of this compile time error message:
    "Windows builds (PLATFORM=mingw) use mk1mf.pl-created Makefiles"
  2. Remove directories apps test tools because they cannot be linked and they are not necessary to cross-compile windows programs that need the openssl library. Error message if not removed is:
    ../libssl.a: could not read symbols: Archive has no index; run ranlib to add one
    respectively after the ar correction, the eerormessages are because of missing windows libraries in the form of:
    ../libcrypto.a(bss_sock.o):bss_sock.c:(.text+0x35e): undefined reference to `_WSAGetLastError@0
  3. Fixing the ar command fixes this error message: libssl.a: could not read symbols: Archive has no index; run ranlib to add one