两个框架具有相同的符号

编程入门 行业动态 更新时间:2024-10-11 09:20:30
本文介绍了两个框架具有相同的符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我的Xcode项目中有两个框架,它们都定义了一个具有相同名称的类(B.framework和C.framework都有一个名为MyClass的类),从而导致一些如下警告:

重复的符号_OBJC_METACLASS _ $ _ MyClass最初在B.framework / B(MyClass.o)现在从C.framework / C(MyClass.o)懒惰加载重复的符号_OBJC_CLASS _ $ _ MyClass最初在B.framework / B(MyClass.o)现在从C.framework / C(MyClass.o)懒惰加载

然后,在运行时,只有一个实现被加载,并尝试使用另一个实现将导致无法识别的选择器发送到实例,因为它们是完全不同的类(即使它们具有相同的名称)。

我在代码中直接使用MyClass实现之一,但另一个框架仅在内部使用MyClass不知道为什么它甚至导出的(它甚至没有在框架头文件中提到,我使用<$

如何使两个框架都可以正常工作?

解决方案

在Obj-C中没有这样的导出类。或者说,没有非出口类的东西。这个问题正是为什么强烈建议在所有Obj-C代码上使用2或3个字母的前缀类。您唯一的解决方案(除了不使用这些框架)是编辑一个(或两个)框架来更改类名称,或者如果您无法访问源代码,那么您需要联系供应商并要求他们做出这个改变。

I have two frameworks in my Xcode project that both define a class with the same name (B.framework and C.framework both have a class named MyClass), resulting in a couple warnings like so:

Duplicate symbol _OBJC_METACLASS_$_MyClass originally in B.framework/B(MyClass.o) now lazily loaded from C.framework/C(MyClass.o) Duplicate symbol _OBJC_CLASS_$_MyClass originally in B.framework/B(MyClass.o) now lazily loaded from C.framework/C(MyClass.o)

Then at run time only one of the implementations is loaded, and trying to use the other one will result in a "unrecognized selector sent to instance" because they are totally different classes (even though they have the same name).

I use one of the MyClass implementations directly in my code, but the other framework only uses its MyClass internally and I have no idea why its even exported (its not even mentioned in the frameworks header files, i used nm to view the symbols).

How can I make both frameworks work?

解决方案

There's no such thing as "exported" classes in Obj-C. Or rather, there's no such thing as "non-exported" classes. This problem is precisely why the use of 2- or 3-letter prefixes on classes is strongly recommended for all Obj-C code. Your only solution (besides not using these frameworks) is to edit one (or both) of the frameworks to change the class name, or if you don't have access to the source, then you need to contact the vendor and ask them to make that change.

更多推荐

两个框架具有相同的符号

本文发布于:2023-07-14 10:29:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1104111.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:符号   框架   两个

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!