简体   繁体   English

grpc.core 的 Xamarin iOS 本机链接失败

[英]Xamarin iOS native linking failed for grpc.core

I've been attempting to make grpc work (ssl http2) on Xamarin Forms and after some pain I managed to get it to work on Android using Grpc.Core.我一直在尝试使 grpc 在 Xamarin Forms 上工作(ssl http2),经过一番痛苦后,我设法使用 Gr 使其在 Android 上工作。 However I couldn't get iOS to compile.但是我无法编译 iOS。 Working through this problem I was trying to get anything grpc related to work on iOS, and eventually found the grpc experimental xamarin demo, HelloworldXamarin.通过这个问题,我试图获得与 iOS 工作相关的任何 grpc,并最终找到了 grpc 实验 xamarin 演示,HelloworldXamarin。 Found here:在这里找到:

https://github.com/grpc/grpc/tree/master/examples/csharp/HelloworldXamarin https://github.com/grpc/grpc/tree/master/examples/csharp/HelloworldXamarin

I downloaded the solution, but when I try to compile it I get the following errors:我下载了解决方案,但是当我尝试编译它时,出现以下错误:

在此处输入图像描述

Error Text:错误文本:

Native linking failed, undefined symbol: operator delete(void*). Please verify that all the necessary frameworks have been referenced and native libraries are properly linked in.

Native linking failed. Please review the build log and the user flags provided to gcc: -LC:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal -lgrpc_csharp_ext -force_load C:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal/libgrpc_csharp_ext.a -LC:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal -lgrpc -force_load C:/g/examples/csharp/HelloworldXamarin/packages/Grpc.Core.2.23.0/build/Xamarin.iOS10/../../native/ios/universal/libgrpc.a

linker command failed with exit code 1 (use -v to see invocation)

For the warning regarding not being able to find libgrpc_csharp_ext.a , I verified that the file was there.对于无法找到libgrpc_csharp_ext.a的警告,我确认该文件在那里。

There appears to be some issue with native linking, which I am very unfamiliar with.本地链接似乎存在一些问题,我对此非常陌生。 I'm using nearly the latest Visual Studio (well, 16.5.3), a mac build host with latest OS and XCode updated to latest.我正在使用几乎最新的 Visual Studio(嗯,16.5.3),一个具有最新操作系统和 XCode 更新到最新的 mac 构建主机。 Didn't make any changes to the files pulled from git.没有对从 git 中提取的文件进行任何更改。 I only just started working with Xamarin iOS this week, so everything should be in a fairly "default" state.我这周才刚刚开始使用 Xamarin iOS,所以一切都应该是相当“默认”的 state。

What could be wrong with my setup/system that makes this not work?我的设置/系统可能有什么问题导致这不起作用? I understand that this is an experimental feature still, but I can't tell if I've done something stupid or if there's been some change in something (like XCode? or it needing VS 2017?) that makes this no longer work?我知道这仍然是一个实验性功能,但我不知道我是否做了一些愚蠢的事情,或者是否有一些变化(比如 XCode?或者它需要 VS 2017?)这使得它不再起作用? Is anyone else able to get this example to compile?有其他人能够编译这个例子吗?

I've also tried newer versions of the grpc nuget packages and that only resulted in more errors.我还尝试过更新版本的 grpc nuget 包,但这只会导致更多错误。

Ultimately I'm trying to get latest Grpc.Core to work in iOS on Xamarin.Forms, though I have very little experience working with iOS. Ultimately I'm trying to get latest Grpc.Core to work in iOS on Xamarin.Forms, though I have very little experience working with iOS. If there are issues with the latest versions of XCode/Visual Studio/Grpc.Core that are causing this, I'm willing to try to work through them, if someone can point me in the right direction.如果最新版本的 XCode/Visual Studio/Grpc.Core 存在导致此问题的问题,如果有人能指出正确的方向,我愿意尝试解决它们。

It is not at all related to your versions or something that you did or didn't do.它与你的版本或你做过或没做过的事情完全没有关系。

First for some theory: If someone wants to use Objective-C libraries or CocoaPods packages in their Xamarin project, they will need to create a binding library for this.首先是一些理论:如果有人想在他们的 Xamarin 项目中使用 Objective-C 库或 CocoaPods 包,他们将需要为此创建一个绑定库 Take it as some sort of a "bridge" between the native implementation and the later exposed C# code that you can use.将其视为本机实现与您可以使用的后来公开的 C# 代码之间的某种“桥梁”。 You can learn more about the binding from the official documentation here and more specifically here .您可以从此处的官方文档中了解有关绑定的更多信息,更具体而言,请参见此处

To sum up the info - after the bindings have been created, you see a .lib or .a file.总结一下信息 - 创建绑定后,您会看到一个.lib.a文件。 This is exactly what they have done - exposed some native code into the libgrpc_csharp_ext.a .这正是他们所做的——将一些本机代码暴露在libgrpc_csharp_ext.a中。 Unfortunately, there are some bindings that are not correct.不幸的是,有些绑定不正确。 This is exactly what you are seeing here - the aftermath of an incorrect binding.这正是您在这里看到的 - 错误绑定的后果。

Looking a bit into the project I got to the following conclusions:稍微研究一下这个项目,我得出以下结论:

  1. There is an open issue from May 2019 about this - https://github.com/grpc/grpc/issues/19172 Unfortunately, the issue is still active and there is no movement there.从 2019 年 5 月起有一个关于此的未解决问题 - https://github.com/grpc/grpc/issues/19172不幸的是,该问题仍然存在,并且没有任何动静。
  2. I have confirmed that after version 1.21 (incl.) the build is not working.我已经确认在1.21 版(包括)之后构建不起作用。 For now, you can downgrade to version 1.20.1 (last known to work).目前,您可以降级到版本1.20.1 (最后一次知道工作)。 I have successfully built the solution with it.我已经成功地用它构建了解决方案。 Please review the changelog and release notes for this specific version (if any) so that you know if it will fit your needs.请查看此特定版本(如果有)的变更日志和发行说明,以便了解它是否符合您的需求。

Basically, you have 2 options:基本上,您有两个选择:

  1. Downgrade to the last good version in order to use it;降级到最后一个好版本才能使用它;

  2. If you want to use the latest version either wait for the issue to be fixed, or fork the repo and help with the fixing.如果您想使用最新版本,请等待问题得到修复,或者 fork 存储库并帮助修复。

If you want to see their build script and help fix the issue, you can start from here .如果您想查看他们的构建脚本并帮助解决问题,您可以从这里开始。

Another useful resource is this video from the official Xamarin channel.另一个有用的资源是来自官方 Xamarin 频道的视频

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM