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

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 ;-)

Stay up-to-date by subscribing to the Comments RSS Feed for this post.

Leave a Comment