Saturday, May 9, 2015

Embedding data in executable

so it's an interesting topic, since you end up with a single file to toss around, which is more manageable. so far the cross platform (linux, w32, ios, android, osx) app i've been working on had no GUI (on the desktop platforms) other than a browser connected via websocket, but then things change, so some GUI was also needed. w32 takes care of this and packs the data neatly inside the executable, but then came the question of what to use on linux and due to my negative experience with qt, decided to try gtk and yep, sure enough, they have their own solution for this too.

so what if it's not gtk, but say, an xlib project, or something even simpler, that needs data :

the options i found :

- resource files, which are the source code representation of your data (eg. gtk)
- data in its own section as part of the executable (ld magic)
- zip appended to the executable (the utter coolness)

a great bunch of options are here : http://stackoverflow.com/questions/4864866/c-c-with-gcc-statically-add-resource-files-to-executable-library .

the ld solution is here : http://stackoverflow.com/questions/4158900/embedding-resources-in-executable-using-gcc/4158997#4158997

and an osx compatible solution is here : http://stackoverflow.com/questions/8923097/compile-a-binary-file-for-linking-osx

EDIT : from the first s/o link, a personal favourite : xxd -i infile.bin outfile.h .

No comments:

Post a Comment