How to deal with the "duplicate symbols" compilation error when adding static libraries to the MAUI iOS Binding Project.

Vasile Javgurean 1 Reputation point
2022-11-18T13:13:05.583+00:00

There is a Xamarin Forms project that relies on some native libraries.
Trying to migrate it to .NET MAUI.
Android native libraries works just fine, same as in Xamarin.
For the iOS added an iOS Binding Project, then added the native libraries similarly as in the Xamarin iOS project.
There are the following libraries:

<ItemGroup>  
    <NativeReference Include="..\..\Libraries\libindy.a">  
      <Kind>Static</Kind>  
      <SmartLink>False</SmartLink>  
    </NativeReference>  

    <NativeReference Include="..\..\Libraries\libsodium.a">  
      <Kind>Static</Kind>  
      <SmartLink>False</SmartLink>  
    </NativeReference>  

    <NativeReference Include="..\..\Libraries\libzmq.a">  
      <Kind>Static</Kind>  
      <SmartLink>False</SmartLink>  
      <IsCxx>True</IsCxx>  
    </NativeReference>`  

There are C libraries (libindy and libsodium) and a C++ one (libzmq). The libindy.a library depends on the libsodium.a and libzmq.a.
In the Xamarin iOS project there is also an additional MTouch argument, which I also added to the MAUI startup project:

<MtouchExtraArgs>-gcc_flags -dead_strip -v</MtouchExtraArgs>

The libraries are fat, so they work on both iPhone and simulator.

The problem is that in MAUI, the application build fails with the following error:
Error: clang++ exited with code 1: duplicate symbol '_crypto_onetimeauth_verify' in: /Users/hetzner/Desktop/TestIndyLibraries/iOSBindingLibrary/bin/Debug/net7.0-ios/iOSBindingLibrary.resources/libsodium.a(libsodium_la-crypto_onetimeauth.o) /Users/hetzner/Desktop/TestIndyLibraries/iOSBindingLibrary/bin/Debug/net7.0-ios/iOSBindingLibrary.resources/libzmq.a(src_libzmq_la-tweetnacl.o)
It found duplicated symbols in libsodium.a and libzmq.a.

I believe that the -dead_strip gcc flag helps to address the issue in Xamarin, but in .NET MAUI it is, unfortunately, not working.
Does someone encounter a similar issue or have an idea on how to solve this?
Thank you.

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,206 questions
{count} votes