I rolled my own system for a C++ web server project that basically took a bunch of files (HTML, CSS, JS, PNGs, etc.) and created C++ headers containing the data encoded as static const char*
. I then #include
those headers where I need access to the data. The app that encodes the 'resource' files executes as a pre-build step. The encoding app itself used boost::filesystem
to create the resource headers, so works on Windows/*nix.
A typical resource file might look like this:
namespace resource
{
// Generated from mainPage.htm
static const char* mainPage_[] =
{
"<html>...</html>"
};
}
For binary content I encode using the \x
notation. I also make sure to line-wrap the data so it is readable in an editor.
I did have some issues though - the MS compiler doesn't allow a static const char*
to be bigger than 64Kb which was a PITA. Luckily the only files larger than this were JavaScript files that I could easily split into smaller chunks - large images would be a problem though.