I am currently updating/writing a delphi binding for lz4 & xxHash.
Project state with compiler error is available here.
Not working line of xxHash.pas
function XXH32 (const AInput: Pointer; ALength: Integer; ASeed: Cardinal): Cardinal; cdecl; external name '_XXH32';
When trying to bind function XXH32 from xxHash.o, it results in the error E2065.
[dcc32 Fehler] xxHash.pas(122): E2065 Ungenügende Forward- oder External-Deklaration: 'XXH32'
What i do not understand, all other functions are bound and working without problems.
When i analyze xxHash.o by creating a dumpfile, the function is present like every other of xxHash.o
Objdump command:
objdump -D xxhash.o > xxhash.o.txt
Dumpfile part of xxH32:
xxhash.o: file format pe-i386
Disassembly of section .text:
00000000 <_XXH32>:
0: 55 push %ebp
1: 57 push %edi
2: 56 push %esi
3: 53 push %ebx
4: 83 ec 14 sub $0x14,%esp
7: 8b 44 24 28 mov 0x28(%esp),%eax
b: 8b 4c 24 2c mov 0x2c(%esp),%ecx
...
Any suggestions?
Minimal Implementation:
program lz4_minimal;
{$APPTYPE CONSOLE}
{$L xxhash.o}
function XXH32 (const AInput: Pointer; ALength: Integer; ASeed: Cardinal): Cardinal; cdecl; external name '_XXH32';
function XXH64 (const AInput: Pointer; ALength: Integer; ASeed: UInt64): UInt64; cdecl; external name '_XXH64';
//necessary dependencies
function _malloc(size: cardinal): Pointer; cdecl;
begin
GetMem(Result, size);
end;
procedure _memcpy(dest, source: Pointer; count: Integer); cdecl;
begin
Move(source^, dest^, count);
end;
procedure _free(P: Pointer); cdecl;
begin
FreeMem(P);
end;
begin
end.
xxHash.o is 32bit for windows, build using MinGW 4.8.1. and the original sourcecode by Yann Collet in revision r36, included in lz4. Makefile is included.
Objectfile can be found on github here
A Workaround, also suggested by David Heffernan, is to add a dummy function to xxHash.c as first function.
The new dumpfile looks like this:
xxhash.o: file format pe-i386
Disassembly of section .text:
00000000 <_XXDUMMY>:
0: b8 2a 00 00 00 mov $0x2a,%eax
5: c3 ret
6: 8d 76 00 lea 0x0(%esi),%esi
9: 8d bc 27 00 00 00 00 lea 0x0(%edi,%eiz,1),%edi
00000010 <_XXH32>:
10: 55 push %ebp
11: 57 push %edi
12: 56 push %esi
....
The project compiles with this hack, the error is gone.
Analyzing the other object files and trying to bind the first referenced functions always results in an error E2065.
There seems to be a general problem with using MinGW and gcc compiled .o files with Delphi.