views:

185

answers:

4

Hi,

I'm looking for a way to embed text files in my binaries (like windows resource system). I need something thats also platform independant (works in windows and linux). I found qt resource management to be what I need but Im not keen on my app depending on qt for this alone. I also found this tool at http://www.taniwha.com/~paul/res/ .. but it is too platform specific.

Regards

Nithin

+1  A: 

If you're using QT 4.5, you can make sure that program is only dependent on one small piece of QT, such as libqtcore. QResource is a part of libqtcore.

supercheetah
A: 

That is not such a great idea. On Linux, for example, data is expected to be installed in a subdirectory of "$datadir" which is, by default, defined to be "$prefix/share", where "$prefix" is the installation prefix. On Mac OS X, resources are expected to be installed in $appbundle/Contents/Resources, where $appbundle is the name of the folder ending in ".app". On Windows, installing data in a folder that is a sibling of the executable is not an uncommon practice. You may be better off using the CMake build system, and using its CPack packaging features for installing/bundling in the default, preferred platform-specific manner.

Although bundling your resources into the executable, itself, may seem cool, it is actually a dangerous idea... for example, will the embedded data be allocated in an executable page? What will happen if you attempt to overwrite or modify the data? What if you want to tweak or modify the data at runtime? Things to think about.

Michael Aaron Safyan
+3  A: 

The xxd utility can be used to create a C source file, containing your binary blobs as an array (with the -i command line option). You can compile that to an object which is linked into your executable.

xxd should be portable to most platforms.

caf
You meant `xxd -i`?
ephemient
Ahh yes, you are correct.
caf
A: 

You can simlpy append all kinds of data to your normal binary. Works in both Windows and Linux. You'll have to open your own binary at runtime and read the data from there.

However, I have to agree that embedding data in binaries is a strange idea. It's common practice to include such data as separate files packaged with the application.

Alexey Feldgendler