2

Im working on a game in c++, and for the first time I wanted to show someone else my work.

Im running into the issue where I can not find out how to complete my .exe file with the needed images inside. I have read a few websites that talk about how it should be done, but nothing that gives all the steps to do it.

If anyone has any solid resource on how this is done I would really appreciate it.

EDIT: Using windows 7 64bit

ixron
  • 127
  • 2
  • 11
  • Can't you just put the images in a special folder, and let the program load them from that folder? When distributing your program, include the folder with the images, maybe create e.g. a Zip archive? – Some programmer dude Jan 19 '13 at 21:07
  • What operating system? Windows executables support resource tables where you can store images, strings, and other information. – Ken White Jan 19 '13 at 21:09

2 Answers2

5

Usually images are not embedded inside the binary file, as this is pretty pointless from a performance point of view (why should you embed millions of bytes of data of a single image inside a binary? Forcing to load all of them together with the executable?).

What is normally done is to have a resource folder, usually relative to the exe working directory, so that your binary is able to load them directly from disk (or whatever device are you using).

When you distribute your game you simply attach everything by maintaining the same folder structure.

According to the technology that you are using what you are asking may be possible but I don't see the point of doing it.

Jack
  • 131,802
  • 30
  • 241
  • 343
  • This sounds like the reason I was getting mixes answers when I was looking for a solution. Thank you. – ixron Jan 19 '13 at 21:19
  • That's not correct. An executable's contents are mapped to virtual pages by ntdll, and only read from disk as a result of a page fault, or on Windows, as a result of prefetching by SysMain. It will only load the whole executable on Windows if `/SWAPRUN:{NET|CD}` is set, and it's being executed from the network or removable media (respectively). Binary assets are typically embedded in an executable using the resource compiler (rc.exe) to compile resource (.res) files into object (.obj) files, which are then provided to the linker. – Zaaier May 14 '22 at 07:58
  • You can also write a helper program to read the asset, and emit a c++ source file declaring an unsigned char array containing the bytes of the assets, then compile the real program using those generated definitions. This is, IMO, a more straightforward approach than using rc.exe. – Zaaier May 14 '22 at 08:02
1

You should look into your linker's documentation, or at least ask the question specifying which linker you use -- it's its job.

For example, this has worked for me at some point:

script:

ld -r -b binary monster_die.wav -o monster_die.o
(link monster_die.o eventually into the executable)

sfx.h:

extern char binary_monster_die_wav_start;
extern char binary_monster_die_wav_end;
static const char* monster_die_wav = &binary_monster_die_wav_start;
static const size_t monster_die_wav_size =
    &binary_monster_die_wav_end - &binary_monster_die_wav_start;
aib
  • 45,516
  • 10
  • 73
  • 79