How to generate Import Library (.lib)
The way Import Library (.lib) is generated depends on two things:
- EXPORTUNFROZEN command in your .mmp file
- .DEF files
Important thing to understand while developing a DLL is use of EXPORTUNFROZEN command in your mmp file, as you are still in development mode, changes to the DLL are expected quite often, hence EXPORTUNFROZEN should be used until you release your DLL. When EXPORTUNFROZEN command is used, Import Library (.dso does similar work as import library .lib) is created as a part of linking process.
What is .Def file
.Def file is Module Definition File which provides information about exported functions, their attributes and ordinals.
Why .Def files are important
- .Def plays an important role in maintaining Binary Compatibility.
- Code using your dll is linked to specific ordinal ( ordinal is an identifier or number given to each of an exported method in your .DEF file ). Hence your ordinals should remain the same other wise the applications which have already been built to use your DLL may not work, and this can be said as Binary Break.
- Hence using .Def file, we maintain the ordinal order such that all the new exported functions are appended to the end preserving the old order which maintains the Binary Compatibility enabling applications which have already been built to use old DLL will work with the new DLL as well.
How to generate .Def File
From Command Line
Build your project in normal way for whatever Platform you want, then use abld freeze command to generate the .DEF file, you will get a message like " File not found - OK if freezing for first time", as it cannot find the .DEF file for freezing.
GoTo >> Project >> Freeze Exports
Where should I place .DEF Files
- By default, the build tools generates / creates BWINS directory for .DEF file for emulator which is at the same level as the directory containing the .mmp file, and similarly the ARM def file in a EABI directory.
- .mmp file does not need to provide location of the .DEF files explicitly, If the files are stored in those above default locations.
- .mmp file should specify the location using the deffile keyword, if you are storing .DEF files in some other location than the default one.
- Now as we have separate .DEF files for each target, you need to use #if defined macros to select the correct .DEF file, depending on the target for which the project is being built.
What happens when I have both EXPORTUNFROZEN and .DEF files
if you have both EXPORTUNFROZEN and .DEF files then import library will be created as a side-effect of linking rather than from the frozen .DEF file, and this import library will be created whether the project is frozen or not.
How to Generate Import Library using EXPORTUNFROZEN
If you have EXPORTUNFROZEN in your .mmp file, then Import Library ( .lib / .dso ) are generated as a part of build process.
How to Generate Import Library using .Def File
Build your dll, If you do not have EXPORTUNFROZEN statement in your mmp file then it wont generate .lib (.dso ) file straight away, first you have to freeze using abld freeze command, it which will generate .Def files and then regenerate makefile (i.e. bldmake bldfiles) then it will create the Import Library from the frozen .DEF files.