strophe / libstrophe

A simple, lightweight C library for writing XMPP clients
http://strophe.im/libstrophe
Other
401 stars 163 forks source link

mingw compiling pre-0.10.0 release - success! #159

Closed dirwiz closed 4 years ago

dirwiz commented 4 years ago

This is probably a worst case scenario cross (static) compiling with Debian 10/mingw gcc v6.3 with c-ares 1.15.0 & openssl 1.1.1g. There are 3 issues when trying to build the library.

Because we are running this from linux, all header file references are case sensitive and need to be lower case

src/resolver.c
-#include <iphlpapi.h>
+#include <Iphlpapi.h>
src/

src/sock.c

-#include <iphlpapi.h>
-#include <mstcpip.h> /* tcp_keepalive */
+#include <Iphlpapi.h>
+#include <Mstcpip.h> /* tcp_keepalive */

The function getline is only defined in libc. I patched examples/register.c with the following code: https://stackoverflow.com/questions/735126/are-there-alternate-implementations-of-gnu-getline-interface/735472#735472

With openssl 1.1.x code you need to include libcrypt32 in your builds -lcrypt32

Hopefully these patches can get in before the 0.10 release gets out. Many thanks for adding C-Ares

pasis commented 4 years ago

Thanks for the info!

As I understand your usecase, you build libstrophe with c-ares and don't need old windows code in the resolver. However, the old code compiles and you get error because of Iphlpapi.h. So, I need to fix that.

Regarding -lcrypt32. Build system gets all required dependencies from pkg-config. However, in your scenario openssl can be misconfigured for cross-compilation. When pkg-config can't find openssl.pc file, configure simply guesses that -lssl -lcrypto is enough. But we cannot hardcode -lcrypto32 there, because it won't work in most cases. As a solution, you can override pkg-config check with the following command:

openssl_CFLAGS="" openssl_LIBS="-lssl -lcrypto32" ./configure

Or, if you think -lcrypto32 must be added in all cases for mingw, we can play with $host_os somehow to handle this specific case.

dirwiz commented 4 years ago

Bit of confusion in your libraries. -lcrypto is part of openssl and is used alongside -lssl. -lcrypt32 is a new library that is required by openssl on windows platforms starting with the 1.1.x code. This is needed to build libstrophe.

I'll admit I'm a bit lost with pkg-config.
I'd say throw it in for all openssl versions. All versions prior to the1.1.x codebase lost support at the beginning of 2020. I don't think it will hurt the prior builds in general anyway. Thanks Eric

pasis commented 4 years ago

First 2 issues should be fixed now. I will get back to lcrypt32 later.

pasis commented 4 years ago

I'm going to close this ticket and won't handle -lcrypt32 in the autotools scripts. The reason is that I would recommend to use more appropriate ways to handle misconfigured openssl. Moreover, different systems will have different dependencies for openssl and configure script just cannot guess all possible variants.

There are 2 ways how to handle custom installations of dependencies: