Project

General

Profile

Issue #1476

Linux to Windows crosscompile mingw64 openssl

Added by Noel Kuntze over 6 years ago. Updated over 6 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Category:
windows
Affected version:
5.4.0
Resolution:

Description

Hello,

I am trying to cross compile strongSwan 5.4.0 from Linux for Window.
For this purpose, I run the following command:

CC=x86_64-w64-mingw32-gcc CFLAGS="-g -O2 -Wall -Wno-pointer-sign -Wno-format-security -Wno-format -mno-ms-bitfields -I/usr/include/" LDFLAGS="-L/home/thermi/FH-Stuff/UNITS-8/Bachelorarbeit/win32-libs/openssl/" ./configure --host=x86_64-w64-mingw32 --disable-defaults --enable-monolithic --enable-static --enable-svc --enable-ikev2 --enable-ikev1  --enable-nonce --enable-pem --enable-pkcs1 --enable-x509 --enable-openssl --enable-socket-win --enable-kernel-wfp --enable-kernel-iph --enable-pubkey --enable-swanctl --with-swanctldir=swanctl --with-strongswan-conf=strongswan.conf

That fails, however, with the following message:
[...]
checking for main in -lcrypto... no
configure: error: OpenSSL libcrypto not found

Am I making a mistake or is this a problem with the source? libcrypto does not exist in the openssl libs for Windows. Instead, libeay32.dll and ssleay32.dll are provided.

History

#1 Updated by Martin Willi over 6 years ago

  • Status changed from New to Feedback

libcrypto does not exist in the openssl libs for Windows. Instead, libeay32.dll and ssleay32.dll are provided.

Yes, and the configure script should check for libeay32 instead of libcrypto on Windows (see https://git.strongswan.org/?p=strongswan.git;a=blob;f=configure.ac#l783). For some reason the configure script does not detect a Windows build, check config.log for details what is going on.

-I/usr/include/

That is probably not what you want when cross-compiling. I'd recommend to use the instructions from the Windows page.

#2 Updated by Noel Kuntze over 6 years ago

Martin Willi wrote:

libcrypto does not exist in the openssl libs for Windows. Instead, libeay32.dll and ssleay32.dll are provided.

Yes, and the configure script should check for libeay32 instead of libcrypto on Windows (see https://git.strongswan.org/?p=strongswan.git;a=blob;f=configure.ac#l783). For some reason the configure script does not detect a Windows build, check config.log for details what is going on.

-I/usr/include/

That is probably not what you want when cross-compiling. I'd recommend to use the instructions from the Windows page.

I started out with the instructions from that page and just added the --host argument, together with the changed paths. I thought it did not matter what openssl headers I chose, as long as they correspond with the DLLs. What is a good place to both get a recent openssl build for Windows together with the headers of it?

#3 Updated by Martin Willi over 6 years ago

from /usr/x86_64-w64-mingw32/include/windows.h:69,
/usr/include/sys/types.h:109:19: error: conflicting types for 'ssize_t'

The /usr/include includes clash with those provided by mingw. The wiki instructions add an include to the Windows openssl headers, but your include points to the Linux include headers.

What is a good place to both get a recent openssl build for Windows together with the headers of it?

https://slproweb.com/products/Win32OpenSSL.html worked fine for me, but building it yourself is not that hard if you follow the OpenSSL instructions.

#4 Updated by Noel Kuntze over 6 years ago

Martin Willi wrote:

from /usr/x86_64-w64-mingw32/include/windows.h:69,
/usr/include/sys/types.h:109:19: error: conflicting types for 'ssize_t'

The /usr/include includes clash with those provided by mingw. The wiki instructions add an include to the Windows openssl headers, but your include points to the Linux include headers.

What is a good place to both get a recent openssl build for Windows together with the headers of it?

https://slproweb.com/products/Win32OpenSSL.html worked fine for me, but building it yourself is not that hard if you follow the OpenSSL instructions.

Well, it actually is kind of hard, because there are no instructions for cross compiling it from Linux to Windows with mingw64 (which is required so I can actually link strongSwan against openssl).

#5 Updated by Noel Kuntze over 6 years ago

I copied the libs and headers from the OpenSSL build from your link to a shared folder between a VM with that build installed and am trying to cross compiel them. It fails with the linker complaining about nof finding -leay32. The headers and the libs come from the same build, so I guess it was built with VisualStudio, so I can not link against it with mingw64?
That's what the build.log says:

/usr/lib/gcc/x86_64-w64-mingw32/6.1.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /home/thermi/VMs/win8.1-sharedfolder//libeay32.dll when searching for -leay32
/usr/lib/gcc/x86_64-w64-mingw32/6.1.1/../../../../x86_64-w64-mingw32/bin/ld: skipping incompatible /home/thermi/VMs/win8.1-sharedfolder//libeay32.dll when searching for -leay32

#6 Updated by Noel Kuntze over 6 years ago

I succeeded in cross compiling openssl and linking strongSwan against it.

#7 Updated by Martin Willi over 6 years ago

  • Status changed from Feedback to Closed

Also available in: Atom PDF