-2

not long ago, I created a game using SDL2 and C++, I wanted to ask if there is a way to "pack" so to speak the dll and the folders full of music images etc. in a single exe (including inside the original exe of course).

if this is a silly question I just got out of college and they didn't teach me how to do this.

Progman
  • 16,827
  • 6
  • 33
  • 48
Abdiel
  • 1

1 Answers1

0

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

Ilian Zapryanov
  • 1,132
  • 2
  • 16
  • 28