简体   繁体   中英

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

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.

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM