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

不想你离开。 提交于 2019-11-30 00:21:21
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.out but with improvements. This is the format used in Mac OS X and iPhone OS libraries for executable files.

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.

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.)

As per apple documentation,

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

Framework target -> Build Settings -> Mach-O Type

Xcode Help has the next description

Mach-O Type (MACH_O_TYPE)[Mach-O file]

This setting determines the format of the produced binary and how it can be linked when building other binaries.

  • Executable: mh_execute. Executables and standalone binaries and cannot be linked.

  • Dynamic Library: mh_dylib. Dynamic libraries are linked at build time and loaded automatically when needed.

  • Bundle: mh_bundle. Bundle libraries are loaded explicitly at run time.

  • Static Library: staticlib. Static libraries are linked at build time and loaded at execution time.

  • Relocatable Object File: mh_object. Object files are single-module files that are linked at build time.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!