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.44k stars 507 forks source link

undefined symbols for architecture arm64 - library crash #20905

Closed Kebechet closed 1 month ago

Kebechet commented 1 month ago

I have created a binding for iOS library Clarity. And the binding crash and I have no idea why.

Steps to Reproduce

  1. Download this repro
  2. Run it on either local or remote iOS device
  3. it will end with error

Expected Behavior

It should initialize the library

Actual Behavior

It ends with error. Error is different for both local & remote devices

[runtime error] - iPhone connected to Windows:

[Build error] - iPhone connected to MAC and remotely run from Windows:

Severity    Code    Description Project File    Line    Suppression State   Details
Error (active)      clang++ exited with code 1:
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$__TtC7Clarity10ClaritySDK", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC7Clarity13ClarityConfig", referenced from:
      objc-class-ref in registrar.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation) MauiApp3 (net8.0-ios)   C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\17.2.8078\targets\Xamarin.Shared.Sdk.targets    1564

Environment

Version information ``` Microsoft Visual Studio Enterprise 2022 Version 17.10.4 VisualStudio.17.Release/17.10.4+35027.167 Microsoft .NET Framework Version 4.8.09032 Installed Version: Enterprise Architecture Diagrams and Analysis Tools 00482-20500-62150-AA814 Microsoft Architecture Diagrams and Analysis Tools Visual C++ 2022 00482-20500-62150-AA814 Microsoft Visual C++ 2022 ADL Tools Service Provider 1.0 This package contains services used by Data Lake tools ASA Service Provider 1.0 ASP.NET and Web Tools 17.10.344.38934 ASP.NET and Web Tools Azure App Service Tools v3.0.0 17.10.344.38934 Azure App Service Tools v3.0.0 Azure Data Lake Tools for Visual Studio 2.6.5000.0 Microsoft Azure Data Lake Tools for Visual Studio Azure Functions and Web Jobs Tools 17.10.344.38934 Azure Functions and Web Jobs Tools Azure Stream Analytics Tools for Visual Studio 2.6.5000.0 Microsoft Azure Stream Analytics Tools for Visual Studio C# Tools 4.10.0-3.24324.8+04fb39164c99c519832109f21b22630bc9246fce C# components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Common Azure Tools 1.10 Provides common services for use by Azure Mobile Services and Microsoft Azure Tools. Entity Framework Core Power Tools 2.5 Adds useful design-time EF Core DbContext features to the Visual Studio Solution Explorer context menu. Extensibility Message Bus 1.4.39 (main@e8108eb) Provides common messaging-based MEF services for loosely coupled Visual Studio extension components communication and integration. Fine Code Coverage FineCodeCoverage2022.ad53fb28-7a11-4465-a27a-3550499ea4a1 Visualize unit test code coverage easily for free in Visual Studio Community Edition (and other editions too) GitHub Copilot 0.2.889.30432 GitHub Copilot is an AI pair programmer that helps you write code faster and with less work. IndentRainbowPackage Extension 1.0 IndentRainbowPackage Visual Studio Extension Detailed Info Microsoft Azure Hive Query Language Service 2.6.5000.0 Language service for Hive query Microsoft Azure Stream Analytics Language Service 2.6.5000.0 Language service for Azure Stream Analytics Microsoft Azure Tools for Visual Studio 2.9 Support for Azure Cloud Services projects Microsoft JVM Debugger 1.0 Provides support for connecting the Visual Studio debugger to JDWP compatible Java Virtual Machines Mono Debugging for Visual Studio 17.10.11 (c9f079d) Support for debugging Mono processes with Visual Studio. NuGet Package Manager 6.10.1 NuGet Package Manager in Visual Studio. For more information about NuGet, visit https://docs.nuget.org/ Project System Tools 1.0 Tools for working with C#, VisualBasic, and F# projects. Razor (ASP.NET Core) 17.10.3.2427201+4f57d1de251e654812adde201c0265a8ca7ca31d Provides languages services for ASP.NET Core Razor. ResX Resource Manager ResXManager Manage localization of all ResX-based resources in one place. Shows all resources of a solution and lets you edit the strings and their localizations in a well-arranged data grid. SQL Server Data Tools 17.10.178.1 Microsoft SQL Server Data Tools Switch Startup Project 4.2.76 Provides a toolbar dropdown box to switch between startup projects. ToolWindowHostedEditor 1.0 Hosting json editor into a tool window TypeScript Tools 17.0.30327.2001 TypeScript Tools for Microsoft Visual Studio Visual Basic Tools 4.10.0-3.24324.8+04fb39164c99c519832109f21b22630bc9246fce Visual Basic components used in the IDE. Depending on your project type and settings, a different version of the compiler may be used. Visual F# Tools 17.10.0-beta.24228.1+dd749058c91585e9b5dae62b0f8df892429ee28f Microsoft Visual F# Tools Visual Studio IntelliCode 2.2 AI-assisted development for Visual Studio. VisualStudio.DeviceLog 1.0 Information about my package VisualStudio.Mac 1.0 Mac Extension for Visual Studio Xamarin 17.10.0.110 (main@cf2e960) Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android. Xamarin Designer 17.10.3.10 (remotes/origin/d17-10@3beef58f89) Visual Studio extension to enable Xamarin Designer tools in Visual Studio. Xamarin Templates 17.9.0 (38e87ba) Templates for building iOS, Android, and Windows apps with Xamarin and Xamarin.Forms. Xamarin.Android SDK 13.2.2.0 (d17-5/45b0e14) Xamarin.Android Reference Assemblies and MSBuild support. 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 Xamarin.iOS and Xamarin.Mac SDK 16.4.0.23 (9defd91b3) Xamarin.iOS and Xamarin.Mac Reference Assemblies and MSBuild support. ```

Build Logs

msbuild.zip

Example Project (If Possible)

Example project showcasing the problem: https://github.com/Kebechet/BUG-repro-2

Binding project used in the repro: https://github.com/Kebechet/Maui.MicrosoftClarity/tree/main/src/Maui.MicrosoftClarity.iOS

Kebechet commented 1 month ago

@rolfbjarne could you please take a look ?

rolfbjarne commented 1 month ago

It looks like the NuGet Kebechet.Maui.MicrosoftClarity.iOS was built from a binding project with NoBindingEmbedding=false. Can you try removing the NoBindingEmbedding=false line from the binding project, rebuild and republish the NuGet and then see if that works?

Kebechet commented 1 month ago

When I removed <NoBindingEmbedding>false</NoBindingEmbedding> then when I built the iOS binding project from my Windows(with connected MAC) the final nuget had only 47kb because it didnt contain the xcframework. Just out of curiosity I tried to build it directly from MAC, the package there was correctly around 6MB but after releasing it as v1.0.1.2 the same problem appeared:

Severity    Code    Description Project File    Line    Suppression State
Error (active)      clang++ exited with code 1:
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$__TtC7Clarity10ClaritySDK", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC7Clarity13ClarityConfig", referenced from:
      objc-class-ref in registrar.o
ld: symbol(s) not found for architecture arm64
clang: error: linker command failed with exit code 1 (use -v to see invocation) SatisFIT.Client.App (net8.0-ios)    C:\Program Files\dotnet\packs\Microsoft.iOS.Sdk\17.2.8078\targets\Xamarin.Shared.Sdk.targets    1564    

PS: I have updated the nuget in the repro

The menioned ios binding is here: https://github.com/Kebechet/Maui.MicrosoftClarity/tree/main/src/Maui.MicrosoftClarity.iOS

And here are steps I did for creating the binding: https://github.com/Kebechet/Maui.MicrosoftClarity/tree/main/src/Maui.MicrosoftClarity.iOS#generating-binding-files

rolfbjarne commented 1 month ago

Your test project builds and runs fine for me now.

Can you get a binlog that shows the build failure?

Kebechet commented 1 month ago

Here: MSBuildReproLogs.zip Can it have something to do with my mac ? I have Mac mini with M1 chip

rolfbjarne commented 1 month ago

Can it have something to do with my mac ? I have Mac mini with M1 chip

No, I have an M1 too.

Does this directory exist on your Windows machine?

C:\Users\samos.nuget\packages\kebechet.maui.microsoftclarity.ios\1.0.1.2\lib\net8.0-ios17.2\Maui.MicrosoftClarity.iOS.resources

or does Clarity.xcframework exist anywhere within the C:\Users\samos.nuget\packages\kebechet.maui.microsoftclarity.ios\1.0.1.2 directory?

Kebechet commented 1 month ago

Does this directory exist on your Windows machine?

If it is copy-pasted then there is a missing backslash between samos and .nuget

Does this directory exist on your Windows machine?

No it doesnt. In: c:\Users\samos\.nuget\packages\kebechet.maui.microsoftclarity.ios\1.0.1.2\lib\net8.0-ios17.2 I have only Maui.MicrosoftClarity.iOS.dll

or does Clarity.xcframework exist anywhere within the

No it doesnt. This is flattened view of the 1.0.1.2 directory: image

I even tried dotnet nuget locals all --clear but no difference after package restoration.

What seems to be quite weird because on nuget website it clearly shows that size of that nuget is 6.13M, so the .xcframework should be packed in the package.

Kebechet commented 1 month ago

So finally I found what was wrong. I had another (local) nuget source specified and that contained the outdated 1.0.1.2 version without embedded .xcframework. Now I can build it as well.

So just to summarize:

But @rolfbjarne I still dont understand 1 thing.

Why was it possible to build the nuget correctly only on Mac ? And not from Windows with remote Mac connected ? Because after removing NoBindingEmbedding the nuget created on Windows didnt contain .xcframework thus size of the package was around 50kb. But when I built it directly from MAC it had 6MB as expected. Is it current limitation on Windows build ? Is it a bug ?

rolfbjarne commented 1 month ago

Why was it possible to build the nuget correctly only on Mac ? And not from Windows with remote Mac connected ?

Can you get a binlog from your Windows build (with a remote Mac connected)?

Kebechet commented 1 month ago

image

MSBuildReproLogs.zip

rolfbjarne commented 1 month ago

MSBuildReproLogs.zip

Thanks for the binlog, I think I know what's going on and it's a bug on our side.

Until this is fixed the workaround is to build on macOS.

Kebechet commented 1 month ago

Alright, thank you very much for your help!