Linking : .a, .lib and .def files

Static libraries on Linux have the .a file extension. Static libraries on Windows have the .lib file extension. Dynamic libraries on Windows have the .dll extension; in order to link against a DLL, an import library is required. The import library is a static library. It contains the code required to load the DLL. Now you’re using GCC (not cl.exe) to compile on Windows. GCC has another file extension convention for import libraries, it “should be called *.dll.a or *.a”, as explained in the doc for the --out-implib you referred to.

Import libraries (.lib with MSVC or .dll.a with GCC) are static libraries: they contain the code to load the DLL. I had the same question the other day.

A DLL may have functions that are exported and functions that are not exported. An import library has to know which functions are exported and which aren’t. One of the means of telling it is a DEF file.

When building the DLL, the linker uses
the .def file to create an export
(.exp) file and an import library
(.lib) file. The linker then uses the
export file to build the DLL file.
Executables that implicitly link to
the DLL link to the import library
when they are built.
— MSDN: Exporting from a DLL Using DEF Files

Also see MSDN: Exporting Functions from a DLL by Ordinal Rather Than by Name, together that should answer your last question on export by index, or ordinal number.

Leave a Comment