xamarin / xamarin-macios

.NET for iOS, Mac Catalyst, macOS, and tvOS provide open-source bindings of the Apple SDKs for use with .NET managed languages such as C#
Other
2.47k stars 512 forks source link

Linker emits "duplicate symbol" errors with Xcode 15 - Microsoft.iOS 16.4.7099 #19115

Closed actus-reus closed 1 year ago

actus-reus commented 1 year ago

Steps to Reproduce

  1. Use Xcode 15 and Microsoft.iOS 16.4.7099
  2. Create a net7.0-ios library project binding to an native library (*.a)
  3. Create a net7.0-ios application project and reference binding library project
  4. Build

Expected Behavior

The application project should build without error or warning as it does with Xcode 14

Actual Behavior

The new Xcode 15 linker reports "duplicate symbols" errors in the native library of the binding project. The error points the duplicated symbols twice to the exact same library and location. No problem with Xcode 14. The only way to make the project compile with Xcode 15 is to fallback to the Xcode 14 classic linker by inserting:

<_MainLinkerFlags Include="-ld64" />

in the application project. But the fallback might be dropped by Apple at any point.

See https://github.com/xamarin/xamarin-macios/pull/18719 and https://developer.apple.com/forums/thread/736590

Environment

Version information ``` Visual Studio Community 2022 for Mac Version 17.6.4 (build 472) Installation UUID: 9be326a3-8594-4e74-8c82-4905d251aaf1 Runtime .NET 7.0.3 (64-bit) Architecture: Arm64 Microsoft.macOS.Sdk 13.1.1007; git-rev-head:8afca776a0a96613dfb7200e0917bb57f9ed5583; git-branch:release/7.0.1xx-xcode14.2 Roslyn (Language Service) 4.6.0-3.23180.6+99e956e42697a6dd886d1e12478ea2b27cceacfa NuGet Version: 6.4.0.117 .NET SDK (Arm64) SDK: /usr/local/share/dotnet/sdk/7.0.308/Sdks SDK Versions: 7.0.308 7.0.307 7.0.304 7.0.203 6.0.414 6.0.413 6.0.410 6.0.408 MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET SDK (x64) SDK Versions: 7.0.400 6.0.414 6.0.413 6.0.410 6.0.106 6.0.102 5.0.408 5.0.405 3.1.426 3.1.420 3.1.416 .NET Runtime (Arm64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 7.0.11 7.0.10 7.0.7 7.0.5 6.0.22 6.0.21 6.0.18 6.0.16 .NET Runtime (x64) Runtime: /usr/local/share/dotnet/x64/dotnet Runtime Versions: 7.0.10 6.0.22 6.0.21 6.0.18 6.0.6 6.0.2 5.0.17 5.0.14 3.1.32 3.1.26 3.1.22 Xamarin.Profiler Version: 1.8.0.49 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Xamarin.Android Version: 13.2.1.2 (Visual Studio Community) Commit: xamarin-android/d17-5/a8a26c7 Android SDK: /Users/emmanuel/Library/Developer/Xamarin/android-sdk-macosx Supported Android versions: 8.0 (API level 26) 12.0 (API level 31) 8.1 (API level 27) 11.0 (API level 30) 10.0 (API level 29) 9.0 (API level 28) 13.0 (API level 33) SDK Command-line Tools Version: 7.0 SDK Platform Tools Version: 34.0.4 SDK Build Tools Version: 32.0.0 Build Information: Mono: d9a6e87 Java.Interop: xamarin/java.interop/d17-5@149d70fe SQLite: xamarin/sqlite/3.40.1@68c69d8 Xamarin.Android Tools: xamarin/xamarin-android-tools/d17-5@ca1552d Microsoft Build of OpenJDK Java SDK: /Library/Java/JavaVirtualMachines/microsoft-11.jdk 11.0.16.1 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Eclipse Temurin JDK Java SDK: /Library/Java/JavaVirtualMachines/temurin-8.jdk 1.8.0.302 Android Designer EPL code available here: https://github.com/xamarin/AndroidDesigner.EPL Android SDK Manager Version: 17.6.0.50 Hash: a715dca Branch: HEAD Build date: 2023-09-07 02:05:26 UTC Android Device Manager Version: 0.0.0.1309 Hash: 06e3e77 Branch: HEAD Build date: 2023-09-07 02:05:26 UTC Apple Developer Tools Xcode: 15.0 22265 Build: 15A240d Xamarin.Mac Version: 9.3.0.6 Visual Studio Community Hash: 97731c92c Branch: xcode14.3 Build date: 2023-04-11 22:38:35-0400 Xamarin.iOS Version: 16.4.0.6 Visual Studio Community Hash: 97731c92c Branch: xcode14.3 Build date: 2023-04-11 22:38:36-0400 Xamarin Designer Version: 17.6.3.9 Hash: 2648399ae8 Branch: remotes/origin/d17-6 Build date: 2023-09-07 02:05:20 UTC Build Information Release ID: 1706040472 Git revision: 0b8c2cb9f01ef14a2b07ff4ea047268c8756fee6 Build date: 2023-09-07 02:03:50+00 Build branch: release-17.6 Build lane: release-17.6 Operating System Mac OS X 13.6.0 Darwin 22.6.0 Darwin Kernel Version 22.6.0 Fri Sep 15 13:41:30 PDT 2023 root:xnu-8796.141.3.700.8~1/RELEASE_ARM64_T8103 arm64 Enabled user installed extensions .NET Core Extensions 0.7 ```

Build Logs

MoveSenseTestApp_Debug_Build_2023-09-29T07_04_08.7561760Z.msbuild.log

Example Project (If Possible)

ld64.zip

Note that the native library had to be removed from the sample project for its size if over 125MB.

dalexsoto commented 1 year ago

This is a known issue, when using Xcode 15, we still recommend using ld_classic this will be fixed once we figure out all the issues on our end with ld_prime so the workaround for now is

<MtouchExtraArgs>-gcc_flags "-Xlinker -ld_classic"</MtouchExtraArgs>
deepshah11295 commented 1 year ago

This is a known issue, when using Xcode 15, we still recommend using ld_classic this will be fixed once we figure out all the issues on our end with ld_prime so the workaround for now is

<MtouchExtraArgs>-gcc_flags "-Xlinker -ld_classic"</MtouchExtraArgs>

where we need to add this @dalexsoto @actus-reus @anaisbetts @radical

actus-reus commented 1 year ago

I used

<ItemGroup>
    <_MainLinkerFlags Include="-ld64" />
 </ItemGroup>

within the \<Project Sdk="Microsoft.NET.Sdk> scope.

deepshah11295 commented 1 year ago

scope

send me the path so I can add it

rolfbjarne commented 1 year ago

This will be fixed in our .NET 8 release, which comes with support for Xcode 15.