How to fix linker errors that say: "Invalid OMF record type 0x21 (possibly COFF)"

3,802 views
Skip to first unread message

江边之鸟

unread,
Oct 28, 2007, 11:21:44 PM10/28/07
to Linux开发联盟
Answer
This error usually occurs when you try to link with a LIB file or an
OBJ file that is not compatible with Borland's OMF file format. This
typically happens when dealing with libraries from third party
vendors. Often times, the third party vendor will supply you with a
LIB file that is in Microsoft's COFF format. The Microsoft COFF format
is incompatible with Borland's OMF format.

The best solution is to obtain Borland compatible files from the third
party vendor. Unfortunately, many third party vendors will simply
ignore you. If this happens to you, your choices are limited.

If the LIB file is an import library for a DLL, you can create a
Borland compatible import library using Borland's IMPLIB tool. All you
need to do is pass IMPLIB the name of the DLL. IMPLIB will generate a
Borland compatible import library. Link with that library instead of
the one from the vendor. Another option is to use Borland's COFF2OMF
tool on the Microsoft import library. I prefer to use IMPLIB if the
DLL is available. For more details on how to call an MSVC DLL from
BCB, see the article at http://www.bcbdev.com/articles/vcdll.htm.

Note:
--------------------------------------------------------------------------------
IMPLIB and COFF2OMF will only work if the library and DLL export
plain, C functions. If they export C++ classes or mangled function
names, then you will get linker errors, or possibly errors while
generating the Borland compatible import library. If you run into this
problem, see the C++ DLL article at http://www.bcbdev.com/articles/vcdll2.htm.
--------------------------------------------------------------------------------

If the LIB file is a static library instead of an import library
(static libraries contain real code, import libraries are just stubs
for DLLs), then the situation becomes more convoluted. You cannot link
MSVC static libraries with your BCB project. You can't easily convert
the library from COFF format to OMF either. Borland's COFF2OMF tool
only works on import libraries. The only clean solution is to use MSVC
to create a DLL or a COM object that wraps the static library. Create
a DLL with MSVC that exports a wrapper function for each routine in
the static library. If the static library contains C++ classes, then
you could be in for a rough ride. Consult the article at
http://www.bcbdev.com/articles/vcdll2.htm. It describes how to wrap a C
++ DLL with a Borland compatible DLL. Static C++ libraries are not
quite the same, but they are very similiar. The techniques involved
are practically the same.

If you have been given raw OBJs, then you follow the same advice from
the preceding paragraph regarding static libraries. Static libraries
are more or less collections of OBJ files. So it makes sense that you
would have to follow the same, rather unpleasant, course of action.
Create an MSVC wrapper DLL for the code in the OBJ, and call the DLL
from your BCB application.

Reply all
Reply to author
Forward
0 new messages