onnxruntime: Linker Problem for MAUI on IOS

Describe the bug When i was building maui ios app on Azure DevOps, it fails to build with the following error. It can be built when <MtouchLink>None</MtouchLink> is added to the csproj. However, App size and build time will be doubled, it is not desireable.

2022-08-02T02:15:41.3706750Z Tool xcrun execution finished (exit code = 1). 2022-08-02T02:15:41.3725910Z
2022-08-02T02:15:41.3727470Z Undefined symbols for architecture arm64: 2022-08-02T02:15:41.3728050Z “OBJC_CLASS$_MLPredictionOptions”, referenced from: 2022-08-02T02:15:41.3729980Z objc-class-ref in onnxruntime(model.o) 2022-08-02T02:15:41.3730730Z “OBJC_CLASS$_MLModelConfiguration”, referenced from: 2022-08-02T02:15:41.3732100Z objc-class-ref in onnxruntime(model.o) 2022-08-02T02:15:41.3732860Z “OBJC_CLASS$_MLModel”, referenced from: 2022-08-02T02:15:41.3733630Z objc-class-ref in onnxruntime(model.o) 2022-08-02T02:15:41.3734990Z “OBJC_CLASS$_MLFeatureValue”, referenced from: 2022-08-02T02:15:41.3735630Z objc-class-ref in onnxruntime(model.o) 2022-08-02T02:15:41.3736260Z “OBJC_CLASS$_MLMultiArray”, referenced from: 2022-08-02T02:15:41.3736960Z objc-class-ref in onnxruntime(model.o) 2022-08-02T02:15:41.3738070Z ld: symbol(s) not found for architecture arm64 2022-08-02T02:15:41.3739440Z clang: error: linker command failed with exit code 1 (use -v to see invocation) 2022-08-02T02:15:41.3743170Z
2022-08-02T02:15:41.3745190Z /Users/runner/hostedtoolcache/dotnet/packs/Microsoft.iOS.Sdk/15.4.402/targets/Xamarin.Shared.Sdk.targets(1214,3): error : clang++ exited with code 1

Urgency None

System information

  • OS Platform and Distribution (e.g., Linux Ubuntu 16.04): MacOS - 12 (Azure DevOps)
  • ONNX Runtime installed from (source or binary): Nuget
  • ONNX Runtime version: 1.12.0
  • Python version: -
  • Visual Studio version (if applicable): -
  • GCC/Compiler version (if compiling from source): -
  • CUDA/cuDNN version: -
  • GPU model and memory: -

To Reproduce Create maui project with onnxruntime. Build for iphone.

Expected behavior it builds.

Screenshots The build task. image

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 2
  • Comments: 19 (13 by maintainers)

Most upvoted comments

It successfully built with the workaround. Thanks.

Short term could you try adding this workaround to your csproj to manually insert CoreML into the frameworks the app links against? Adjust the ‘Condition’ if needed.

<!-- Manually add CoreML to the frameworks we link against. -->
<Target Name="AddCoreML" Condition="'$(TargetFramework)' == 'net6.0-ios'" AfterTargets="_LoadLinkerOutput" BeforeTargets="_ComputeLinkNativeExecutableInputs">
    <ItemGroup>
        <_LinkerFrameworks Include="CoreML" />
    </ItemGroup>
</Target>

We were able to reproduce the issue in a CI. The sample app builds without a problem (so local builds and testing are fine). It’s the ‘publish’ phase that seems to be the issue with some coreml symbols used by the ORT library going missing. We’ll contact the MAUI folks to investigate given that’s not something (AFAIK) we have any control over the behaviour of.

Can you please provide the output from dotnet --info as well as the full command line/s and output from your attempt to build the sample app so we can make sure we’re testing exactly the same way?

Can you also run a build of the sample app to produce a binlog and share the log here? Use the -bl parameter. By default it will output to a file called msbuild.binlog in the current directory.