14

My 32 bit Delphi 2010 application links to a number of C object files using the $LINK compiler directive. Can I do this in Delphi XE2 when targetting 64 bit?

I am currently compiling using bcc32 version 5.5, but I don't mind which compiler I use if it turns out that the Embarcadero C compiler does not yet output 64 bit objects.

David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490

2 Answers2

34

Yes. You must compile the "C" objects files to COFF format. This usually means either the Intel and/or MSVC++ compilers. The same caveats apply to 64bit object file linking that apply to 32bit. You must ensure that all external references are properly resolved, either by providing another .obj which has that symbol, or from Delphi code. When building the "C" code, make sure you disable any stack checks or other run-time verification code generation. Many times such codegen relies on a specific version of the C/C++ RTL from the given tool.

Something else worth noting is that while Delphi 64bit can link to COFF object files (eventually it will also support ELF64), 32bit Delphi supports linking with C++Builder built OMF object files and, new to XE2, 32bit COFF object files which can be built with MSVC++. The same caveats apply.

Allen Bauer
  • 16,657
  • 2
  • 56
  • 74
  • Thank you so much for replying Allen, this is exactly what I wanted to hear. I think at long last I'm about to come back to SA. One more question if you please, do you know if gcc/mingw produces objects that can be consumed by Delphi? – David Heffernan Sep 01 '11 at 18:32
  • 6
    It's also worth mentioning that the System.Win.Crtl.pas unit provides support for linking in many of the basic C runtime routines that are needed when linking in .obj files. This unit is part of the RTL package. See the comments / disclaimer / warning in the source file before you use it. :) – Mark Edington Sep 15 '11 at 05:38
  • 1
    About OBJ formats (if e.g. you ask why the same file extension may have several formats), see http://agner.org/optimize site. It is updated frequently, contains a lot of interesting material, especially about 64 bit and cross-platform. There is even a converter between COFF/OMF formats, and some cross-platform decompiler. – Arnaud Bouchez Oct 03 '11 at 10:21
3

Yes, you can link to OBJ files in 64-bit XE2 projects, but the OBJ files have to be 64-bit code.

Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477