4

is there any tool like Borland "coff2omf.exe"for converting Borland OMF LIB format to MS VC++ COFF LIB format ?

actually i want to create .obj file in delphi and use that in MSVC++ .

Behrooz
  • 684
  • 1
  • 9
  • 19

2 Answers2

7

Yes, there is such a tool.

See this tool.

This utility can be used for converting object files between COFF/PE, OMF, ELF and Mach-O formats for all 32-bit and 64-bit x86 platforms. Can modify symbol names in object files. Can build, modify and convert function libraries across platforms. Can dump object files and executable files. Also includes a very good disassembler supporting the SSE4, AVX, AVX2, FMA and XOP instruction sets. Source code included (GPL). Manual.

Note that this http://www.agner.org web site is the best resource I know about low-level optimization. All the linked information is worth reading, if you want to deal with performance.

But for using the Delphi-generated .obj with VC++, it won't be easily feasible, but for very small part of code. You will need the Delphi RTL used in your code. An external .dll is much better. Note also that some types (like strings or dynamic arrays) won't be easily modifiable in VC++.

Arnaud Bouchez
  • 42,305
  • 3
  • 71
  • 159
  • 1
    Have you any experience with this tool? I've never had any luck with it. – David Heffernan Jun 03 '13 at 09:13
  • 1
    I played with it a lot of time. Works perfectly. But most of the time, you need to know low-level asm stuff, of course. – Arnaud Bouchez Jun 03 '13 at 09:15
  • I guess by the time you've cut the Pascal down to something that makes no use of the Delphi RTL, it's easy enough to port it to C! – David Heffernan Jun 03 '13 at 09:19
  • 1
    thanks all i think my problem solved :Microsoft linker and library manager can convert from 32-bit OMF to COFF. The Editbin tool that comes with Microsoft compilers can convert from 32-bit OMF to COFF and modify COFF files. – Behrooz Jun 03 '13 at 09:20
  • @DavidHeffernan You are right: in fact, I used this tool to execute C code in a Delphi program, and not the contrary. Main purpose was for using good floating-point computation (with which Delphi does not shine), some third-party library, and/or some low-level asm/opcodes (e.g. VIA padlock execution). The same .obj has been used on both Windows and Linux (without any PIC use, of course). – Arnaud Bouchez Jun 03 '13 at 15:41
  • @ArnaudBouchez I wonder if you would edit your answer to say this. I'm sceptical that that tool will do what is being asked here. And what's more I'm rather perplexed by Behrooz's last comment. I find that hard to believe. – David Heffernan Jun 03 '13 at 16:05
4

To the best of my knowledge there is no such tool. Using Agner Fog's object file converter, the tool that Arnaud refers to, I've never succeeded in converting a Delphi unit into a COFF .obj that can be linked to an MSVC program.

I do believe that it's not realistic to take Delphi source code, compile it, and then use the generated object in MSVC. The other direction is quite possible. You can compile C code to an object, and link that object to your Delphi executable. When you do this you need to resolve any dependencies that the compiled object has.

But to link a Delphi object into a C/C++ program is going to require whatever part of the Delphi RTL that you use. And that's going to be tricky unless you happen not to use any part of the Delphi RTL, which seems unlikely.

In your situation I think your options are:

  1. Port the code to C or C++.
  2. Compile the Delphi code into a dynamic library and link to that from your C++ program.
David Heffernan
  • 601,492
  • 42
  • 1,072
  • 1,490
  • :thank you for your advice ,but i think it's possible. one of my old friend accomplished this work he converted delphi .obj to coff and used in vc++ dll for a AV engine. (excuse me for my bad English) – Behrooz Jun 03 '13 at 09:00
  • I've never found anything that works. I was never able to make the tool that Arnaud refers to work with Borland OMF. – David Heffernan Jun 03 '13 at 09:12