What is Mach-O type should I use it in my iOS Objective-C project?
Asked Answered
D

2

2

What is Mach-O type in Build Setting in Xcode? and what should it be Set on?

it has these options "Executable" "Dynamic Library" "Bundle" "Static Library" "Relocatable Object File"

I had an error "Apple Mach-O Linker Error Group" since I changed it from Executable to Static Library my error went off, I wanna know is that ok that I changed it? and what all those options mean so I won't face another error in the future.

Despatch answered 25/7, 2017 at 10:16 Comment(0)
N
3

enter image description here

For more detail Building Mach-O Files and Xcode Build Setting Reference

Nidifugous answered 25/7, 2017 at 10:20 Comment(0)
D
2

Mach-O Type(MACH_O_TYPE)

[Framework static vs dynamic]

[Mach-O format]

Official page which has some reflection in loader.h. Additionally MH_PRELOAD 0x5, MH_CORE 0x4, MH_DYLINKER 0x7

To setup Mach-O Type determines a linker behaviour

Framework target -> Build Settings -> Mach-O Type
  • Executable 0x2 (mh_execute/mh_executable) - Is not linked. Is used to create a launchable program - Application, App extension - Widget. Application target is a default setting
  • Bundle 0x8 (mh_bundle .bundle) - loadable bundle - run time linked. iOS now supports only Testing Bundle target where it is a default setting to generate a Loadable bundle.
    System -> Testing Bundle -> tested binary. A location of Testing Bundle will be depended on target, static or dynamic binary...
  • Dynamic Library 0x6 (mh_dylib .dylib or none) - Load/run time linked.
    • With Framework target - Dynamic Library is a default setting to generate a Dynamic framework
  • Static Library(staticlib .a) - Compilation time(build time) linked.
    • With Static Library target - Static Library is a default setting to generate a Static library
    • With Framework target - Static Library to generate a Static framework
  • Relocatable Object File 0x1 (mh_object .o) - Compilation time(build time) linked. It is the simplest form. It is a basement to create executable, static or dynamic format. Relocatable because variables and functions don't have any specific address

It is useful to use otool to determine if binary is dynamic or not -h or -hv

-h     Display the Mach header.
-v     Display verbosely (symbolically) when possible.
otool -h <path_binary>
//e.g.
otool -h "/Users/alex/Desktop/projects_experiments/ios/LibraryAndFramework/BuildCustom/UtilsSwift/UtilsSwiftFramework.framework/UtilsSwiftFramework"

Mach header
      magic  cputype cpusubtype  caps    filetype ncmds sizeofcmds      flags
 0xfeedfacf 16777228          0  0x00           6    30       3488 0x00100085

filetype is a key point - 6 - 0x6 - Dynamic Library

[Vocabulary]

Dovekie answered 4/4, 2020 at 21:53 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.