Is there any way to convert COFF library (lib file) to OMF library for using with C++Builder6 ? This coff is not just import library, it conatians some code. When I try to convert it using borland's coff2omf.exe, I get 1KB file from 15KB file.
5 Answers
Instead of DigitalMars converter, you may use the Object file converter -- objconv
-- available at agner.org/optimize
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, AVX512, FMA3, FMA4, XOP and Knights Corner instruction sets. Source code included (GPL).
This is a great site for low-level optimization, and there are a lot of useful information in the associated manual PDF file, about the library formats across several platforms.

- 20,597
- 9
- 86
- 152

- 42,305
- 3
- 71
- 159
It's fairly typical for an OMF object file to be a lot smaller than an equivalent COFF object, so what you're getting may well be valid.
If you find that it's really not, you can probably break the lib file into individual object files, disassemble the object files, re-assemble them to OMF object files, and put those together into an OMF lib file.

- 476,176
- 80
- 629
- 1,111
-
Thank you for your answer. Can you recommend me tools which I can use to disassemble COFF obj files and then re-assembler them to OMF obj files? – CITBL Jun 25 '10 at 14:09
-
Assuming you're running on Windows, you can disassemble a COFF object with `dumpbin /disasm the_file.obj`. That produces output that's sort of ready for MASM, though you'll have to strip off some extra columns it throws in. If you don't mind spending some money, *IDA Pro* will produce results ready to feed to MASM directly. Either way, I'd probably do the assembling with MASM. – Jerry Coffin Jun 25 '10 at 14:24
-
Jerry, would you be able to provide some examples of the commands to run for MASM? I'm trying to do this, and am not sure how to invoke MASM (or what columns need to be removed from the `dumpbin` output). – Mark LeMoine Nov 30 '11 at 00:28
-
@MarkLeMoine: The usual invocation of MASM is just `ml /c source_file.asm`. As far as dumpbin goes, you'll use `dumpbin /disasm object_file`, and then cut out the sections of source code. At least in most cases, you'll need to do some hand-work to add (at least) things like CPU, MODEL and END directives, probably PROC/ENDP appropriately, etc. On the left side you'll have an address and instruction bytes you'll also need to cut off, leaving only the actual instructions/operands. It uses the addresses as labels, so you'll need to add real labels at the appropriate spots as well. – Jerry Coffin Nov 30 '11 at 00:33
It may be worth noting that in newer versions of Delphi (>= XE2), the compiler accepts COFF as well as OMF. It's probably also true for C++ Builder. The 64 bit compilers use only COFF. See here for more informations about linking COFF.

- 20,597
- 9
- 86
- 152
This is rather late, but if anyone is looking for an answer, you can checkout COFFIMPLIB from DigitalMars. COFF2OMF is available at the same site, but it looks like that's older.

- 757
- 8
- 20
Integrating Delphi (omf) and Ada (gcc, coff) required lots of effort until I've given up doing it in a single exe.
I honestly tried to disintegrate gcc rtl and ada rtl .a (coff libraries) into lots of .o (objects), convert them via coff2omf (there were DMD coff2omf and iirc another convobj or so). Some of the coff .o failed to be converted to .obj so I can't say if it was a reliable way at all.
Assembler level conversion is not so simple when it takes to exceptions and other deep details.
It's a pity I haven't tried a tool named ftp://ftp.styx.cabel.net/pub/UniLink/
It's not obvious, but UniLink can probably be used to achieve the goal. One of its targets is C++ Builder package (both dynamic and static). unilink -Tpp -GI
should do the trick

- 20,597
- 9
- 86
- 152

- 618
- 6
- 12