Wednesday, February 12, 2014

Embedding Resource Files in a Cocoa Foundation Command Line Tool

Drew McCormack:

Graham Lee and several others pointed me to two standard solutions: you can use the linker to embed the files in the __text section of the Mach-O binary, or you can use a tool called xxd to convert the file’s data to a C array, and include that directly in your source code. I ended up with the second solution, which I will explain further below. I didn’t investigate using the linker, but Quinn “The Eskimo!” assures me that you use getsectXXX APIs to extract the data at run time. (Update: Daniel Jalkut has a post describing this approach.)

1 Comment RSS · Twitter

And with the compiler attribute 'section' to specify custom section to store some data, you can combine both technics: using xdd to create C array, and reading them using getsectXXX.

Note that I don't think there is any benefit to using this technic but doing useless thing is part of the fun ;-)

Leave a Comment