Search code examples
iosxcodecompilationcoremlmach-o

How to compile resource files into a custom framework or static library or Mach-O file?


How to compile resource files into a custom framework or static library (meaning into a Mach-O file)? Thanks for any tips.


Solution

  • Assuming by "resource files" you mean arbitrary binary files, you can include them into any binary by creating an assembly file (e.g. resources.S) like so:

    .section __RESOURCE,__file1
    _symbol_file1:
    .incbin "file1.zip"
    .no_dead_strip _symbol_file1
    
    .section __WHATEVER,__file2
    _symbol_file2:
    .incbin "file2.bin"
    .no_dead_strip _symbol_file2
    
    // etc, you get the pattern
    

    If you don't have a project in which you can include this file already, then you can turn it into an iOS arm64 framework by itself like so:

    mkdir MyResources.framework
    xcrun -sdk iphoneos clang -arch arm64 -shared -o MyResources.framework/MyResources resources.S