简体   繁体   English

在Delphi XE4 Win64平台中无法使用由cl.exe编译的C.OBJ文件

[英]Unable to use C's .OBJ files compiled by cl.exe in Delphi XE4 Win64 platform

I want to translate 7Zip's SDK to Delphi/Pascal's unit file. 我想将7Zip的SDK转换为Delphi / Pascal的单位文件。 First, I try compile the C files using BCC32.exe for Win32 platform: 首先,我尝试使用用于Win32平台的BCC32.exe编译C文件:

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. 它产生的.OBJ文件很少,而且我可以在Delphi单元中毫无问题地使用这些对象。

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: 然后,我尝试使用用于Win64平台的BCC64.exe编译这些目标文件:

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: 这次,它生成的.o文件很少,但是在编译Delphi单元时出现错误:

[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. 我了解到,Delphi Win64可以识别的目标文件格式是64位COFF,而BCC64.exe可以生成ELF64格式。

I then try to use cl.exe from Microsoft Windows SDK to produce both Win32 and Win64 .OBJ files, 然后,我尝试使用Microsoft Windows SDK中的cl.exe生成Win32和Win64 .OBJ文件,

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? 有什么想法如何使用cl.exe生成可以由Win32和Win64平台中的Delphi单元编译的.OBJ文件吗?

It is a bit confusing, but in Delphi, 这有点令人困惑,但是在Delphi中,

  • for 64 bit, you can use 64 bit COFF files as produced by, for instance, Microsoft's 64 bit compiler. 对于64位,您可以使用由Microsoft的64位编译器生成的64位COFF文件。 Delphi XE6 64 bit is reportedly capable of linking with 64 bit ELF files too, as C++Builder 64 bit produces them. 据报道,Delphi XE6 64位也能够链接64位ELF文件,因为C ++ Builder 64位会生成它们。

  • for 32 bit, you can use 32 bit OMF C object files, as produced by C++Builder. 对于32位,您可以使用C ++ Builder生成的32位OMF C对象文件。 Delphi XE2 and newer (see this link from David Heffernan's comment) allow you to link to 32 bit COFF too. Delphi XE2和更高版本(请参阅David Heffernan的评论中的此链接 )也允许您链接到32位COFF。

Some more info on the subject: Using C object files in Delphi 有关此主题的更多信息: 在Delphi中使用C对象文件

So since Delphi XE6, you can actually use C++Builder to generate Delphi-linkable object files for both platforms again. 因此,从Delphi XE6开始,您实际上可以使用C ++ Builder再次为两个平台生成可与Delphi链接的目标文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM