使用 Objective Sharpie 将 Objective-C 库绑定到 C# 时遇到问题 [英] Trouble binding Objective-C library to C# with Objective Sharpie

查看:28
本文介绍了使用 Objective Sharpie 将 Objective-C 库绑定到 C# 时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试浏览本指南:

I'm attempting to walk through this guide:

https://developer.xamarin.com/guides/ios/advanced_topics/binding_objective-c/walkthrough/

尝试为这个 github 项目创建绑定:

trying to create bindings for this github project:

https://github.com/lminhtm/LMGaugeView

使用 Sharpie 3.4.

Using Sharpie 3.4.

我遇到了以下问题:

  1. 我无法生成具有架构 i386 armv7 x86_64 arm64 的 Fat 二进制文件,因为我是针对 iOS11 构建的.我只能生成具有架构 x86_64arm64 的 Fat 二进制文件,尝试其他给我的错误消息 iOS 部署版本无效,iOS 10 是最大部署目标对于 32 位目标.这是预期的吗?

  1. I cannot generate a Fat binary with the architectures i386 armv7 x86_64 arm64 because I am building against iOS11. I can only generate a Fat binary with architectures x86_64 and arm64, attempting the others gives me the error message invalid iOS deployment version, iOS 10 is the max deployment target for 32-bit targets. Is this expected?

当我使用 Sharpie 时,我能够生成 API 和 Struct 文件,但是,这些文件中的每一个都非常庞大,Structs 以 24K+ 行和 API 54K+ 行结束.我也跟着一个 youtube 教程,他得到的输出大约是 200 行左右,所以我的如此巨大的事实让我觉得有些事情正在发生.他的教程不是针对我的同一个 Objective-C 项目的,但我什至尝试了他做的相同的教程,最终得到了相同的结果.

When I then use Sharpie I am able to generate the API and Struct files, however, each of these files are huge, with Structs ending up at 24K+ lines, and API 54K+ lines. I followed a youtube tutorial as well and the output he got was about 200 or so lines, so the fact that mine are so huge makes me think something is going on. His tutorial wasn't for my same Objective-C project but I even tried the same one he did and ended up with the same result.

Struct 文件最终有超过 7K 的错误,我看到无数行看起来像:

The Struct file ends up have over 7K errors, and I see countless lines that look something like:

// extern long double tanhl (long double) __attribute__((const)) __attribute__((nothrow));
[DllImport ("__Internal")]
[Verify (PlatformInvoke)]
static extern [unsupported Builtin: long double] tanhl ([unsupported Builtin: long double]);

它缺少标识符名称并且有这个 [不支持的内置:我不明白的部分.

Where it's missing identifier names and has this [unsupported Builtin: piece I don't understand.

还有无数对其他 iOS 版本、watchOS 和 TV 的引用,因此它似乎正在尝试为每个操作系统和版本创建 API 和结构,这说明为什么文件会如此之大.这是 Struct 文件中的一个小片段:

There's also countless references to other iOS versions, and watchOS and TV, so it seems like it's trying to create the API and Structs for every OS and version there is, which makes sense why the files would be so large. Here's a small snippet from the Struct file:

    // extern CGPathRef _Nullable CGPathCreateCopyByTransformingPath (CGPathRef _Nullable path, const CGAffineTransform * _Nullable transform) __attribute__((availability(ios, introduced=5.0))) __attribute__((cf_audited_transfer));
    [iOS (5,0)]
    [DllImport ("__Internal")]
    [Verify (PlatformInvoke)]
    [return: NullAllowed]
    static extern unsafe CGPathRef* CGPathCreateCopyByTransformingPath ([NullAllowed] CGPathRef* path, [NullAllowed] CGAffineTransform* transform);

    // extern CGMutablePathRef _Nullable CGPathCreateMutableCopy (CGPathRef _Nullable path) __attribute__((availability(ios, introduced=2.0))) __attribute__((cf_audited_transfer));
    [iOS (2,0)]
    [DllImport ("__Internal")]
    [Verify (PlatformInvoke)]
    [return: NullAllowed]
    static extern unsafe CGMutablePathRef* CGPathCreateMutableCopy ([NullAllowed] CGPathRef* path);

    // extern CGMutablePathRef _Nullable CGPathCreateMutableCopyByTransformingPath (CGPathRef _Nullable path, const CGAffineTransform * _Nullable transform) __attribute__((availability(ios, introduced=5.0))) __attribute__((cf_audited_transfer));
    [iOS (5,0)]
    [DllImport ("__Internal")]
    [Verify (PlatformInvoke)]
    [return: NullAllowed]
    static extern unsafe CGMutablePathRef* CGPathCreateMutableCopyByTransformingPath ([NullAllowed] CGPathRef* path, [NullAllowed] CGAffineTransform* transform);

我知道这些文件应该更小,尤其是因为 Objective-C 代码是单个头文件.我在这里做错了什么?

I know these files should be way smaller, especially since the Objective-C code is a single header file. What could I be doing wrong here?

如果需要,我可以提供更多详细信息!

I can provide more details if needed!

推荐答案

我快速检查了您提到的 LMGaugeView pod.

I quickly checked the LMGaugeView pod that you mentioned.

事实证明,为此您必须拥有最新的 XCode 和 Sharpie(3.4 是当前版本).

Turns out, for that you have to have latest XCode and Sharpie (3.4 is current version).

您可以通过运行sharpie update 来更新sharpie.然后你可以生成一个绑定.

You can update sharpie by running sharpie update. Then you can generate a binding.

我试过了,它似乎工作得很好,看看你自己:youtube.com/watch?v=g7qQJnMxubU&feature=youtu.be

I've tried and it seems to work just fine, see yourself: youtube.com/watch?v=g7qQJnMxubU&feature=youtu.be

无耻插件 - 我在视频中使用的工具是我用于 Xamarin.iOS 绑定的sharpie 的包装器 - objc-automatic.

Shameless plug - tool I used in video is a wrapper for sharpie I use for Xamarin.iOS bindings - objc-automatic.

这篇关于使用 Objective Sharpie 将 Objective-C 库绑定到 C# 时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆