Embed data in a C++ program Embed data in a C++ program sqlite sqlite

Embed data in a C++ program


You can use objcopy to bind the contents of the file to a symbol your program can use. See, for instance, here for more information.


Use macros. Technically that file would be source code file but it wouldn't look like this.Example:

//queries.incl - SQL queriesQ(SELECT * FROM Users)Q(INSERT [a] INTO Accounts)//source.cpp#define Q(query) #query,char * queries[] = {#include "queries.incl"};#undef Q

Later on you could do all sorts of other processing on that file by the same file, say you'd want to have array and a hash map of them, you could redefine Q to do another job and be done with it.


You can always write a small program or script to convert your text file into a header file and run it as part of your build process.