You can do that, and it's not a silly question, since a lot of applications are embeding some assets (icons, small wav files, even shaders) into the exe. You need to generate a .h
file that is linked into your program. The header shall contain an array of the binary data and the size of the array for ex.
#pragma once
char binarydata[] = {0xaa, 0xff....};
size_t binarydatasize = sizeof(binarydata)/sizeof(binarydata[0]);
So in prebuild step, you have to read your binary file, dump it into that generated header (you may see binutils
for Linux or write your own script that generates C header file and when you are done, you will want to load it into your program somehow. Usually you will have
extern binarydata[];
extern size_t binarydatasize;
in your application so your loader (let's assume it accepts void*
for data and size_t
for size knows that those are declared somewhere int the binary, so thus you embed the binary data directly into the executable.
Also there is a good answer here too: Embedding resources in executable using GCC