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

2

37

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 :

  1. Executable
  2. Dynamic Library
  3. Bundle
  4. Static Library
  5. Relocatable Object File

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.

Stannfield answered 26/10, 2012 at 6:50 Comment(1)
H
45

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.)
Hellion answered 26/10, 2012 at 7:13 Comment(3)
Are you sure "Relocatable Object File" is another word for a dynamic library? AFAIK, it's object file (which is linked statically when used - so this is another form of static static library). While static libraries contain multiple objects, relocatable object file is a single object.Muscid
I think it is not the same as ELF relocatable object file. Can someone double check?Muscid
I am using cocoa pods in project. If i set my cocoa pod framework as Static Library instead of Dynamic Library. Will cause any issue ??Iodize
F
8

As per apple documentation,

Mach-O Type Definition

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

Finegrain answered 26/10, 2012 at 7:14 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.