Keywords: Create .lib file from .dll file, Visual Studio, Programming
Recently I was working with a 3rd party win .dll file and having trouble to compile my code as I did not have required .lib file. Microsoft Visual Studio provides a way to create necessary .lib file form .dll file. Follow the steps given below to create .lib file from .dll file.
Step 1: Open the Visual Studio Command Prompt
Start ->Programs ->Microsoft Visual Studio -> Tools-> Visual Studio Command Prompt |
Step 2: Execute the ‘dumpbin‘ command to get a list of all exported functions of your .dll file.
<dumpbin></exports><path-to-your-.dll-file> |
For example, I have a .dll file techawarey.dll file in my C:\ drive so I’ll execute the command as :
dumpbin /exports C:\techawarey.dll
This will print quite a bit of text to the console. However we are only interested in the functions:
Microsoft (R) COFF/PE Dumper Version 10.00.30319.01Copyright (C) Microsoft Corporation. All rights reserved. Dump of file C:\techawarey.dll File Type: DLL Section contains the following exports for techawarey.dll 00000000 characteristics 4D41CCA9 time date stamp Fri Jan 28 01:21:05 2013 0.00 version 1 ordinal base
10 number of functions 10 number of names ordinal hint RVA name 1 0 00017770 show_techawarey_logo 2 1 00017710 change_techawarey_logo 3 2 000176C0 create_techawarey_new_post 4 3 000156D0 delete_techawarey_new_post 5 4 00016D90 old_techawarey_old_post …etc |
Step 3: Copy all those function names (only the names) and paste them into a new text file.
Step 4: Name the text file ‘yourlib.def’ and put the line “EXPORTS” at its top.
For example, techawarey.def looks like as:
EXPORTS
show_techawarey_logo
change_techawarey_logo
create_techawarey_new_post
delete_techawarey_new_post
old_techawarey_old_post
…
Step 5: Now execute ‘lib‘ command to crate .lib file from .def file.
<lib> </def:><path-of-def-file></OUT:><path-of-lib-file> |
For example, lib /def:C:\techawarey.def /OUT:C:\techawarey.lib
You should see an output like this:
c:\Program Files\Microsoft Visual Studio 10.0\VC>lib /def:C:\techawarey.def /OUT:D:\techawarey.libMicrosoft (R) Library Manager Version 10.00.30319.01Copyright (C) Microsoft Corporation. All rights reserved.LINK : warning LNK4068: /MACHINE not specified; defaulting to X86 Creating library D:\techawarey.lib and object D:\techawarey.exp |
Your .lib file is ready to use in your project now. Please Like and Share… 😉 🙂