HaxeFoundation / hxcpp

Runtime files for c++ backend for haxe
Other
295 stars 182 forks source link

Conflicts when static linking a library that uses mbedtls #1126

Closed tobil4sk closed 1 month ago

tobil4sk commented 1 month ago

In static builds of lime projects, lime's mbedtls conflicts with hxcpp's (more info at https://github.com/openfl/lime/pull/1767). This will be a problem especially with the mbedtls 3 upgrade (#1113).

I'm not sure if this might be the same issue as #777, because that talks about including .lib files.

There are two possible solutions I can think of.

Solution 1: Hxcpp uses lime's mbedtls

Solution 2: Lime uses hxcpp's mbedtls

@hughsando I was wondering if you have any thoughts?

* EDIT: there is no need for this, as including the same sources twice doesn't seem to cause issues.

tobil4sk commented 1 month ago

I'm working on using solution 2, and I've had some luck. In a hacky way, it's possible to link against mbedtls of current and old hxcpp versions just by using hxcpp_ssl. The flags haven't changed too much since it was introduced, so it should be backwards compatible as well. This includes SSL.cpp which is unwanted, but it's a minor inconvenience and can be solved for future versions by rearranging the hxcpp xml files as suggested (see #1133).

One issue I ran into was that MBEDTLS_NET_C has been undefined in the mbedtls config since https://github.com/HaxeFoundation/hxcpp/commit/e5003a3c51aab903b06272e12520bb6230732adc. This causes linking issues with the current version of cURL that lime is using (because it uses functions from net_sockets.c). Luckily updating cURL avoids this issue, but it would be best to remove this #undef from the hxcpp config to make it more universal: #1128.

tobil4sk commented 1 month ago

As mentioned in #1133:

An external static library built with hxcpp that wants to link with mbedtls can now use:

  • <include name="${HXCPP}/project/thirdparty/mbedtls-flags.xml" /> to include the necessary compilation flags for compiling a source files that want to include mbedtls headers (i.e. include paths and defines)
  • <include name="${HXCPP}/project/thirdparty/mbedtls-files.xml" /> so that <files id="mbedtls" /> can be added to a target to link mbedtls.