Can I link a plain file into my executable?

c, c++, embedded-resource, gcc, linker

Solution

You could do this:

objcopy --input binary \
        --output elf32-i386 \
        --binary-architecture i386 my_file.xml myfile.o

This produces an object file that you can link into your executable. This file will contain these symbols that you'll have to declare in your C code to be able to use them

00000550 D _binary_my_file_xml_end
00000550 A _binary_my_file_xml_size 
00000000 D _binary_my_file_xml_start

Problem

Some frameworks (Qt, Windows, Gtk...) offer functionality to add resources to your binaries. I wonder if it would be possible to achieve this without the framework, since all that is really needed is - a symbol to contain the resource's address within the binary (data segment) - a symbol to represent the length of the resource - the resource itself How can this be achieved with the gcc toolchain?

Original source

Related problems