[fpc-pascal] Placing binary data (resources) in object files?

Anthony Walter sysrpl at gmail.com
Mon Jun 3 18:51:59 CEST 2013


Wow, thanks for all the interesting replies. In the mean time here is what
I came up with:

 ld -r -b binary -o binary.o helloworld.txt

#include <stdint.h>

extern char _binary_helloworld_txt_start[];
extern char _binary_helloworld_txt_end[];

void* helloworld(uintptr_t* i) {
uintptr_t a = (uintptr_t)&_binary_helloworld_txt_start;
uintptr_t b = (uintptr_t)&_binary_helloworld_txt_end;
(*i) = b - a;
return &_binary_helloworld_txt_start;
}

gcc -c -o test.o test.c
ar rcs libtest.a test.o binary.o

program testresources;

type
  TExternResource = function(out Size: UIntPtr): Pointer;

function ResString(Res: TExternResource): string;
var
  P: Pointer;
  I: UIntPtr;
begin
  P := Res(I);
  SetLength(Result, I);
  Move(PChar(P)[0], PChar(Result)[0], I);
end;

function helloworld(out Size: UIntPtr): Pointer; cdecl; external;

{$linklib test}

var
  S: string;
begin
  S := ResString(@helloworld);
  WriteLn(S);
end.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20130603/0ef40bfb/attachment.html>


More information about the fpc-pascal mailing list