使用 Xamarin 链接 ObjC 库的问题 [英] Issues Linking ObjC Library using Xamarin

查看:52
本文介绍了使用 Xamarin 链接 ObjC 库的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

过去几天我一直致力于绑定我的第一个 ObjC 库 (SVGKit).我已经完成了所有的构建和编译,但是当被另一个项目引用时我无法运行它.

I've been working on binding my first ObjC library (SVGKit) for the past few days. I've got it all building and compiling but I'm unable to get it running when referenced by another project.

我的绑定代码可以在这里找到:https://github.com/jamesmundy/SVGKit.Xamarin

My code for the binding can be found here: https://github.com/jamesmundy/SVGKit.Xamarin

运行时,显示如下错误:

When run, the following error is displayed:

无法创建该类型的本机实例'SVGKitBindings.SVGKImageView':本机类尚未加载.可以通过设置忽略此条件ObjCRuntime.Class.ThrowOnInitFailure 为 false.

Could not create an native instance of the type 'SVGKitBindings.SVGKImageView': the native class hasn't been loaded. It is possible to ignore this condition by setting ObjCRuntime.Class.ThrowOnInitFailure to false.

我检查了我正在使用的静态库,它支持以下平台:

I've checked the static library I'm using and it supports the following platforms:

fat 文件中的架构:libSVGKit-iOS.1.2.0.a 是:armv7 i386x86_64 arm64

Architectures in the fat file: libSVGKit-iOS.1.2.0.a are: armv7 i386 x86_64 arm64

我相信这就是我所需要的.

I believe this is all I need.

我的链接器文件如下:

[程序集:LinkWith("libSVGKit-iOS.1.2.0.a", LinkTarget.ArmV7 |LinkTarget.Simulator, SmartLink = true, ForceLoad = true)]

[assembly: LinkWith ("libSVGKit-iOS.1.2.0.a", LinkTarget.ArmV7 | LinkTarget.Simulator, SmartLink = true, ForceLoad = true)]

我是否必须以不同的方式配置我正在使用此绑定的项目?非常感谢您帮助加载本机库.

更新 1: 感谢建议,我尝试编辑链接器文件以支持与静态库相同的平台,但不幸的是它没有解决问题.现在文件如下:

Update 1: Thanks to a suggestion I tried editing the Linker file to support the same platforms as the static library, unfortunately it didn't solve the problem. The file is now as follows:

[程序集:LinkWith("libSVGKit-iOS.1.2.0.a", LinkTarget.ArmV7 |LinkTarget.Simulator |LinkTarget.Arm64 |LinkTarget.Simulator64,SmartLink = true,ForceLoad = true)]

[assembly: LinkWith ("libSVGKit-iOS.1.2.0.a", LinkTarget.ArmV7 | LinkTarget.Simulator | LinkTarget.Arm64 | LinkTarget.Simulator64, SmartLink = true, ForceLoad = true)]

我也在所有模拟器上尝试了代码,但不幸的是仍然没有运气.

I also tried the code on all the emulators, but still had no luck unfortunately.

推荐答案

在确定了我的代码和项目的一些问题后,我能够解决这个问题.

I was able to solve this problem after having identified a few issues with my code and the project.

  • Linker.cs 文件实际上并未与项目一起构建.尽管它在解决方案中,但并没有被编译,因此它包含的将库链接在一起的重要信息丢失了.

  • The Linker.cs file was not actually building with the project. Although it was in the solution it wasn't being compiled and therefore the important information it contained to link the libraries together was missing.

SVGKit 使用了几个框架.我没有在链接器文件中引用这些,还需要一些其他的链接器标志.当我解决了这个问题时,文件看起来像这样:

SVGKit uses several framework. I was not referencing these in the linker file and there were some other linkerflags needed. When I had solved this issue the file looked like this:

[程序集:LinkWith("libSVGKit-iOS.1.2.0.a", LinkTarget.ArmV7 |LinkTarget.Simulator |LinkTarget.Arm64 |LinkTarget.Simulator64,SmartLink = true, Frameworks="QuartzCore CoreText CoreGraphicsCoreImage UIKit", LinkerFlags="-lxml2 -ObjC", ForceLoad = true)]

[assembly: LinkWith ("libSVGKit-iOS.1.2.0.a", LinkTarget.ArmV7 | LinkTarget.Simulator | LinkTarget.Arm64 | LinkTarget.Simulator64, SmartLink = true, Frameworks="QuartzCore CoreText CoreGraphics CoreImage UIKit", LinkerFlags="-lxml2 -ObjC", ForceLoad = true)]

这篇关于使用 Xamarin 链接 ObjC 库的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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