在OSX上链接到iOS模拟器二进制文件 [英] Linking to iOS simulator binaries on OSX

查看:107
本文介绍了在OSX上链接到iOS模拟器二进制文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很好奇,如果我链接到Mac应用程序中的iOS模拟器框架,会发生什么.因此,我将UIKit复制到了它自己的文件夹中(因此,框架搜索路径不会包含所有iOS模拟器框架,就像CoreFoundation在Mac和iOS上都一样,但具有不同的标题),然后将其拖到Xcode的链接部分中. Xcode给我的错误是:

I was curious what would happen if I linked to an iOS simulator framework in a Mac app. So I copied UIKit to it's own folder (so the Framework search path wouldn't include all the iOS simulator framework, as like CoreFoundation is both on Mac and iOS but has different headers), and dragged it into the link section in Xcode. The error Xcode gave me was:

为MacOSX构建,但与为iOS Simulator构建的dylib链接 文件'/Users/jonathan/Desktop/macuikit/UIKit.framework/UIKit' 架构x86_64

building for MacOSX, but linking against dylib built for iOS Simulator file '/Users/jonathan/Desktop/macuikit/UIKit.framework/UIKit' for architecture x86_64

这两种架构都是x86_64,因此如何分辨该框架是专门针对iOS模拟器的,我删除了对Info.plist之类的所有对iOS的引用,甚至尝试删除了UIKit二进制文件之外的所有内容,但是出现了相同的错误.它自身的二进制文件中是否有某些内容可以告诉链接程序它可以在哪个平台上运行,而不仅仅是体系结构?我看了看Mach-O标头,但只有CPU类型和子类型的字段,而且都没有像预期的那样为模拟器提供值.

Both architectures are x86_64, so how can it tell the framework is specifically for the iOS simulator, I removed all references to iOS in things like Info.plist, even tried deleted everything but the UIKit binary, but the same error came up. Is there something in the binary it self that tells the linker which platform it can run on, rather than just the architecture? I looked at the Mach-O header but there is only fields for CPU type and subtype, and neither has a value for the simulator as expected.

推荐答案

经过一番挖掘,事实证明二进制文件中确实指定了可以运行该库的平台.实际上,您可以在自己喜欢的Hex编辑器中编辑二进制文件,并使链接程序完全跳过此检查.

After a little bit of digging, it turns out that the platform on which the library can run on is indeed specified in the binary. In fact, you can edit the binary in your favorite Hex editor and make the linker skip this check entirely.

未在Mach-O标头中指定此信息(您已经意识到).而是将其指定为装入命令类型.您可以通过浏览 LLVM源来查看可用的类型.具体来说,枚举值LC_VERSION_MIN_MACOSXLC_VERSION_MIN_IPHONEOS看起来很有趣.

This information is not specified in the Mach-O header (as you have already realized). Instead, it is specified as a load command type. You can see the available types by digging through the LLVM sources. Specifically, the enum values LC_VERSION_MIN_MACOSX and LC_VERSION_MIN_IPHONEOS look interesting.

现在,在我们的二进制文件中找到偏移量.在MachOView(或任何其他编辑器/查看器或您选择的)中打开相同的文件,并记下偏移量:

Now, find the offset for this in our binary. Open the same in MachOView (or any other editor/viewer or your choice) and note the offset:

一旦记下了偏移量,请在十六进制编辑器中跳转至相同位置并进行更新.我将LC_VERSION_MIN_IPHONEOS(25)修改为LC_VERSION_MIN_MACOSX(24)

Once the offset is noted, jump to the same in a Hex editor and update it. I modified LC_VERSION_MIN_IPHONEOS (25) to LC_VERSION_MIN_MACOSX (24)

保存更新,然后尝试再次链接.该错误应消失.当然,当您尝试实际运行示例时,还会遇到其他问题.有趣的LLDB然后:)

Save the updates and try linking again. The error should go away. Of course, you will hit other issues when you try to actually run your example. Have fun with LLDB then :)

这篇关于在OSX上链接到iOS模拟器二进制文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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