Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There are a couple possibilities:</p> <ul> <li><p>use ld's capability to turn any file into an object (<a href="https://stackoverflow.com/questions/2627004/embedding-binary-blobs-using-gcc-mingw">Embedding binary blobs using gcc mingw</a>):</p> <pre><code>ld -r -b binary -o binary.o foo.bar # then link in binary.o </code></pre></li> <li><p>use a <code>bin2c</code>/<code>bin2h</code> utility to turn any file into an array of bytes (<a href="https://stackoverflow.com/questions/225480/embed-image-in-code-without-using-resource-section-or-external-images/225658#225658">Embed image in code, without using resource section or external images</a>)</p></li> </ul> <hr> <p>Update: Here's a more complete example of how to use data bound into the executable using <code>ld -r -b binary</code>:</p> <pre><code>#include &lt;stdio.h&gt; // a file named foo.bar with some example text is 'imported' into // an object file using the following command: // // ld -r -b binary -o foo.bar.o foo.bar // // That creates an bject file named "foo.bar.o" with the following // symbols: // // _binary_foo_bar_start // _binary_foo_bar_end // _binary_foo_bar_size // // Note that the symbols are addresses (so for example, to get the // size value, you have to get the address of the _binary_foo_bar_size // symbol). // // In my example, foo.bar is a simple text file, and this program will // dump the contents of that file which has been linked in by specifying // foo.bar.o as an object file input to the linker when the progrma is built extern char _binary_foo_bar_start[]; extern char _binary_foo_bar_end[]; int main(void) { printf( "address of start: %p\n", &amp;_binary_foo_bar_start); printf( "address of end: %p\n", &amp;_binary_foo_bar_end); for (char* p = _binary_foo_bar_start; p != _binary_foo_bar_end; ++p) { putchar( *p); } return 0; } </code></pre> <hr> <p>Update 2 - Getting the resource size: I could not read the _binary_foo_bar_size correctly. At runtime, gdb shows me the right size of the text resource by using <code>display (unsigned int)&amp;_binary_foo_bar_size</code>. But assigning this to a variable gave always a wrong value. I could solve this issue the following way: </p> <pre><code>unsigned int iSize = (unsigned int)(&amp;_binary_foo_bar_end - &amp;_binary_foo_bar_start) </code></pre> <p>It is a workaround, but it works good and is not too ugly.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload