I want to translate 7Zip's SDK to Delphi/Pascal's unit file. First, I try compile the C files using BCC32.exe
for Win32 platform:
bcc32.exe -c -D_LZMA_PROB32 -D_WIN32 -v -y Threads.c LzFind.c LzFindMt.c LzmaDec.c LzmaEnc.c
It produces few .OBJ
files and I am able to use these objects in Delphi units without problem.
unit Threads;
interface
uses System.Win.Crtl, Winapi.Windows, LzmaTypes, System.Classes;
{$Z4}
type
TCEvent = THandle;
TCSemaphore = THandle;
TCCriticalSection = TRTLCriticalSection;
TCAutoResetEvent = TCEvent;
TCThread = THandle;
TThread_Func_Type = Pointer;
function __beginthreadex(__security_attr: Pointer; __stksize: Cardinal; __start:
TThread_Func_Type; __arg: Pointer; __create_flags: Cardinal; var
__thread_id: Cardinal): Cardinal; cdecl; external msvcrt name _PU +
'_beginthreadex';
function _Event_Reset(var p: TCEvent): TWRes; cdecl; external name _PU +
'Event_Reset';
function _Event_Set(var p: TCEvent): TWRes; cdecl; external name _PU +
'Event_Set';
function _Handle_WaitObject(h: THandle): TWRes; cdecl; external name _PU +
'Handle_WaitObject';
function _Semaphore_Release1(var p: TCSemaphore): TWRes; cdecl; external name
_PU + 'Semaphore_Release1';
function _HandlePtr_Close(var h: THandle): TWRes; cdecl; external name _PU +
'HandlePtr_Close';
function _CriticalSection_Init(var p: TCCriticalSection): TWRes; cdecl; external
name _PU + 'CriticalSection_Init';
function _AutoResetEvent_CreateNotSignaled(var p: TCAutoResetEvent): TWRes;
cdecl; external name _PU + 'AutoResetEvent_CreateNotSignaled';
function _Semaphore_Create(var p: TCSemaphore; initCount: UInt32; maxCount:
UInt32): TWRes; cdecl; external name _PU + 'Semaphore_Create';
function _Thread_Create(var p: TCThread; func: TThread_Func_Type; param:
LPVOID): TWRes; cdecl; external name _PU + 'Thread_Create';
implementation
{$ifdef Win64}
{$L Win64\Threads.o}
{$else}
{$L Win32\Threads.obj}
{$endif}
end.
I then attempt to compile these object files using BCC64.exe
for Win64 platform:
bcc64.exe -c -D_LZMA_PROB32 -D_WIN64 -v -y Threads.c LzFind.c LzFindMt.c LzmaDec.c LzmaEnc.c
This time, it produces few .o
files but I get errors when compile the Delphi unit:
[dcc64 Fatal Error] LzFind.pas(128): F2084 Internal Error: AV0756F5D3-R2D06DB90-0
I learned that the object file format recognized for Delphi Win64 is 64 bit COFF whereas BCC64.exe produces ELF64
format.
I then try to use cl.exe
from Microsoft Windows SDK to produce both Win32 and Win64 .OBJ
files,
cl.exe -c -D_LZMA_PROB32 -D_WIN32 Threads.c LzFind.c LzFindMt.c LzmaDec.c LzmaEnc.c
x86_amd64\cl.exe -c -D_LZMA_PROB32 -D_WIN64 Threads.c LzFind.c LzFindMt.c LzmaDec.c LzmaEnc.c
but I get these errors:
[dcc32 Error] Threads.pas(64): E2065 Unsatisfied forward or external declaration: '__imp__CloseHandle@4'
[dcc32 Error] Threads.pas(64): E2065 Unsatisfied forward or external declaration: '__imp__GetLastError@0'
[dcc32 Error] Threads.pas(64): E2065 Unsatisfied forward or external declaration: '__imp__InitializeCriticalSection@4'
Any ideas how to use cl.exe
to produce .OBJ
files that may compiled by Delphi unit in both Win32 and Win64 platform?