在 Xcode 项目目标构建设置中,什么是 Mach-O 类型?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13082149/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:56:34  来源:igfitidea点击:

In Xcode project target build settings, What is Mach-O Type?

objective-ciosxcodelinkerllvm

提问by Max

After getting tired of numerous Match-O linker error, I want to know that this thing means. Instead of trial and error solution, I would like to know the concept behind these things. Specifically I want to know the difference between :

在厌倦了无数的 Match-O 链接器错误后,我想知道这意味着什么。我想知道这些东西背后的概念,而不是反复试验的解决方案。具体来说,我想知道以下之间的区别:

  1. Executable
  2. Dynamic Library
  3. Bundle
  4. Static Library
  5. Relocatable Object File
  1. 可执行
  2. 动态库
  3. 静态库
  4. 可重定位目标文件

These are the options presented when I click on Mach-O Type settings on Linking section. Some small definition or some link to appropriate content is ok too.

这些是我在链接部分单击 Mach-O 类型设置时显示的选项。一些小的定义或一些适当内容的链接也可以。

回答by Srikar Appalaraju

Mach-O, short for Mach object file format, is a file format for executables, object code, shared libraries, dynamically-loaded code, and core dumps. For unix users this is like a.outbut with improvements. This is the format used in Mac OS X and iPhone OS libraries for executable files.

Mach-O是 Mach 目标文件格式的缩写,是一种用于可执行文件、目标代码、共享库、动态加载代码和核心转储的文件格式。对于 unix 用户来说,这就像a.out但有所改进。这是 Mac OS X 和 iPhone OS 库中用于可执行文件的格式。

As you know iOS devices (iPhone, iPad etc.) have different architectures ARMv6 (iPhone 2G + 3G, iPod Touch) and ARMv7 (iPhone 3GS, iPod Touch 2G + 3G) but the simulators used in Xcode runs mostly on i386 platform. This means the that the library clients have to setup separate targets for the simulator and device. The separate targets duplicate most information, and only differ in the static libraries included. So if you are getting a Mach-O linker error what it means is that xcode is having trouble linking to one of the libraries for that target device; as a result of which compilation fails.

如您所知,iOS 设备(iPhone、iPad 等)具有不同的架构 ARMv6(iPhone 2G + 3G、iPod Touch)和 ARMv7(iPhone 3GS、iPod Touch 2G + 3G),但 Xcode 中使用的模拟器主要在 i386 平台上运行。这意味着库客户端必须为模拟器和设备设置单独的目标。单独的目标复制了大部分信息,仅在包含的静态库中有所不同。因此,如果您遇到 Mach-O 链接器错误,则意味着 xcode 无法链接到该目标设备的库之一;因此编译失败。

Now your definitions -

现在你的定义——

  1. Executable - compiled machine targeted program ready to be run in binary format.
  2. Dynamic Library - are linked during runtime -- a program with references to a dynamic library will load and link with the library when it starts up (or on demand).
  3. Bundles - and bundle identifier let iOS and OSX recognise any updates to your app. It gives it a unique presence in the app.
  4. Static Library - files are linked at build time. code is copied into the executable. Code in the library that isn't referenced by your program is removed. A program with only static libraries doesn't have any dependencies during runtime.
  5. Relocatable Object File - is another word for a dynamic library. When you link with a dynamic library, the addresses of the functions contained within are computed, based on where the library is loaded in memory. They are "relocatable" because the addresses of the contained functions are not determined at link time. (In a static library, the addresses are computed during link time.)
  1. 可执行文件 - 已编译的机器目标程序准备以二进制格式运行。
  2. 动态库 - 在运行时链接 - 引用动态库的程序将在启动时(或按需)加载并链接到该库。
  3. 捆绑包 - 和捆绑包标识符让 iOS 和 OSX 识别您的应用程序的任何更新。它使它在应用程序中具有独特的存在感。
  4. 静态库 - 文件在构建时链接。代码被复制到可执行文件中。库中未被您的程序引用的代码将被删除。只有静态库的程序在运行时没有任何依赖项。
  5. 可重定位目标文件 - 是动态库的另一种说法。链接动态库时,将根据库在内存中的加载位置计算其中包含的函数的地址。它们是“可重定位的”,因为所包含函数的地址不是在链接时确定的。(在静态库中,地址是在链接时计算的。)

回答by iDev

As per apple documentation,

根据苹果文档,

Mach-O Type Definition

Mach-O 类型定义

Check this for more details Building Mach-O Filesand Xcode Build Setting Reference

检查此以获取更多详细信息构建 Mach-O 文件Xcode 构建设置参考