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

Real Device only - cannot build project due to undefined symbols #20628

Closed tuyen-vuduc closed 1 month ago

tuyen-vuduc commented 1 month ago

Steps to Reproduce

  1. Clone this repo
  2. Follow the readme to setup prerequisites
  3. Open src/quickstart/dotnet-mapboxqs.sln
  4. Try compile the iOS for real device

Expected Behavior

Build and run successfully

Actual Behavior

Compilation error as reported here.

/usr/local/share/dotnet/packs/Microsoft.iOS.Sdk/17.2.8053/targets/Xamarin.Shared.Sdk.targets(3,3): Error: clang++ exited with code 1:
Undefined symbols for architecture arm64:
  "_OBJC_CLASS_$_MBXExceptionHandler", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC10MapboxMaps10CameraView", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC10MapboxMaps14GestureHandler", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC10MapboxMaps15AttributionView", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC10MapboxMaps15CameraDebugView", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC10MapboxMaps16PaddingDebugView", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC10MapboxMaps17DistanceFormatter", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC10MapboxMaps17PanGestureHandler", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC10MapboxMaps17SizeTrackingLayer", referenced from:
      objc-class-ref in registrar.o
  "_OBJC_CLASS_$__TtC10MapboxMaps18InfoBu (DotnetIOS.MapboxQs)

Environment

Both on Visual Studio for Mac and Visual Studio for Windows

Version information ``` Visual Studio Community 2022 for Mac Version 17.6.12 (build 410) Installation UUID: 4aa146b2-a6e4-454d-91e4-49bcb76de15e Runtime .NET 7.0.3 (64-bit) Architecture: X64 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 (x64) SDK: /usr/local/share/dotnet/sdk/8.0.300/Sdks SDK Versions: 8.0.300 8.0.100 7.0.406 7.0.313 7.0.312 7.0.311 7.0.310 7.0.309 7.0.308 7.0.306 7.0.304 7.0.302 6.0.422 6.0.421 6.0.420 6.0.419 6.0.418 6.0.417 6.0.416 6.0.415 6.0.414 6.0.410 6.0.408 5.0.408 3.1.426 MSBuild SDKs: /Applications/Visual Studio.app/Contents/MonoBundle/MSBuild/Current/bin/Sdks .NET Runtime (x64) Runtime: /usr/local/share/dotnet/dotnet Runtime Versions: 8.0.5 8.0.0 7.0.16 7.0.15 7.0.14 7.0.13 7.0.12 7.0.11 7.0.9 7.0.7 7.0.5 6.0.30 6.0.29 6.0.28 6.0.27 6.0.26 6.0.25 6.0.24 6.0.23 6.0.22 6.0.18 6.0.16 5.0.17 3.1.32 Xamarin.Profiler Version: 1.8.0.49 Location: /Applications/Xamarin Profiler.app/Contents/MacOS/Xamarin Profiler Updater Version: 11 Apple Developer Tools Xcode: 15.4 22622 Build: 15F31d Xamarin.Mac Version: 9.3.0.23 Visual Studio Community Hash: 9defd91b3 Branch: xcode14.3 Build date: 2023-10-23 16:14:59-0400 Xamarin.iOS Version: 16.4.0.23 Visual Studio Community Hash: 9defd91b3 Branch: xcode14.3 Build date: 2023-10-23 16:15:00-0400 Xamarin.Android Version: 13.2.2.0 (Visual Studio Community) Commit: xamarin-android/d17-5/45b0e14 Android SDK: /Users/tuyen/Library/Android/sdk Supported Android versions: 12.1 (API level 32) 8.0 (API level 26) 12.0 (API level 31) 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: 35.0.1 SDK Build Tools Version: 34.0.0 rc1 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: 2024-05-08 22:24:22 UTC Android Device Manager Version: 0.0.0.1309 Hash: 06e3e77 Branch: HEAD Build date: 2024-05-08 22:24:22 UTC Xamarin Designer Version: 17.6.3.9 Hash: 2648399ae8 Branch: remotes/origin/d17-6 Build date: 2024-05-08 22:24:17 UTC Build Information Release ID: 1706120410 Git revision: 2f8e0518dd80a933901821bac53f7398d4b61c0f Build date: 2024-05-08 22:22:37+00 Build branch: release-17.6 Build lane: release-17.6 Operating System Mac OS X 14.4.1 Darwin 23.4.0 Darwin Kernel Version 23.4.0 Fri Mar 15 00:11:05 PDT 2024 root:xnu-10063.101.17~1/RELEASE_X86_64 x86_64 ```

Build Logs

Example Project (If Possible)

Link to the GitHub repo was mentioned above.

tuyen-vuduc commented 1 month ago

Additional info

rolfbjarne commented 1 month ago

The reason the symbols can't be found is because they're private:

$ nm -m ~/Library/Caches/XamarinBuildDownload/MapboxMaps-11.3.0.1/artifacts/MapboxMaps.xcframework/ios-arm64/MapboxMaps.framework/MapboxMaps|grep '_OBJC_CLASS_$__TtC10MapboxMaps10CameraView'
00000000002c18c0 (__DATA,__objc_data) non-external (was a private external) _OBJC_CLASS_$__TtC10MapboxMaps10CameraView

how does this work for Xcode projects? Do you have a working Xcode projects using these xcframeworks?

tuyen-vuduc commented 1 month ago

@rolfbjarne You can check and run the ObjC repository. the sample app can run on the device without issue. (not all samples were ported or corrected after version upgrade.

The above mentioned class is exposed in -Swift.h header file. Let me try remove that binding class to see what happens.

tuyen-vuduc commented 1 month ago

@rolfbjarne Removing reported symbols works. Let me observe a bit more. Will there be an updated version for Sharpie to check the symbol this way as well to remove this kind of issue?

rolfbjarne commented 1 month ago

the sample app can run on the device without issue. (not all samples were ported or corrected after version upgrade.

I tried real quick the ObjC repository, but ran into some problems.

In any case, the question is if the ObjC project can use these types that are private (such as CameraView for instance)?

Will there be an updated version for Sharpie to check the symbol this way as well to remove this kind of issue?

Probably not, Sharpie reads the header file, and the header doesn't specify which classes are private and which classes are public.

IMHO the problem seems to be with the header: it shouldn't contain private API in the first place.

microsoft-github-policy-service[bot] commented 1 month ago

Hi @tuyen-vuduc. Due to inactivity, we will be closing this issue. Please feel free to re-open this issue if the issue persists. For enhanced visibility, if over 7 days have passed, please open a new issue and link this issue there. Thank you.