如何确定 Mac OS X 上静态库 (.a) 的目标体系结构?
我有兴趣验证给定的 iPhone 静态库是否是为 ARM 或 Intel 构建的。
好奇心胜过一切。 是否有某种 Mac OS X 或 BSD 特定工具可以执行此操作? 这篇帖子给出了一个例子Linux。
I'm interested in verifying if a given iPhone static library has been built for ARM or Intel.
It's more curiosity than anything. Is there some kind of Mac OS X or BSD specific tool to do this? This post gives an example in Linux.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
另一种选择是
lipo
; 它的输出比otool
的输出更简短且更具可读性。一个例子:
Another option is
lipo
; its output is brief and more readable thanotool
's.An example:
file
可能会告诉你。otool
当然应该可以。 但我会先尝试file
,例如
带有存档的示例:
file
will probably tell you.otool
certainly should be able to. But I'd tryfile
first,e.g.
Example with archive:
正如前面提到的,
file
并不总是有效。otool -hv -arch all
可能是保证工作的最接近的东西 - 它提供了库中每个目标文件的体系结构信息。例子:
As mentioned earlier,
file
does not always work.otool -hv -arch all
is probably the closest thing that is guaranteed to work - it gives architecture information for every single object file in the library.Example:
如果有人来这里寻找有关如何判断库(或其中的目标文件)是否适用于 Mac Catalyst 的答案,请使用
otool -l
转储加载命令。 查找任何对象的 LC_BUILD_VERSION 部分。 Mac Catalyst 由平台 6
标识,而不是平台 1
。If anyone comes here looking for answers about how to tell whether a library (or the object files in it) are intended for Mac Catalyst, use
otool -l
to dump the load commands. Find the LC_BUILD_VERSION section for any object. Mac Catalyst is identified byplatform 6
rather thanplatform 1
.此 bash 脚本将帮助您以编程方式将体系结构列表放入变量中。
list_archs.sh:
使用示例:
This bash script will help you programmatically get a list of architectures into a variable.
list_archs.sh:
Usage example:
作为替代方案,我发现 objdump 可以很好地工作。 例如,在我的环境中,我使用 vxWorks 构建库档案,并需要将它们链接到其他项目中。 为了测试存档是否是正确的体系结构,我可以执行如下操作(bash 语法):
这个示例并不完全正确,因为确实显示了一些行,但没有说 elf32-sparc-vxworks,但这很容易足以适应这一点。
这样做的一个好处是,大多数 *nix 操作系统上都安装了 objdump 或类似名称的变体,而其他响应中建议的工具却没有安装。
编辑我刚刚想到OP在OSX上询问。 我很抱歉。
As an alternative, I've found
objdump
can work well. As an example, in my environment I build library archives with vxWorks and need to link those into other projects. To test whether the archive is the correct architecture, I could do something like the following (bash syntax):This example isn't precisely correct, because some lines DO show up that don't say elf32-sparc-vxworks, but it's easy enough to adapt this.
One nice benefit of this is that
objdump
, or a similarly named variant, is installed on most *nix operating systems, whereas tools suggested in other responses aren't.edit It just occurred to me the OP was asking on OSX. My apologies.