Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a .lib file when have a .dll file and a header file

I am trying to create an application in visual studio that will be able to access a .dll file that already exists. I need the application to call up routines. I also have a header file that already exists.

I have been researching on the internet and have found that I need to create a .lib file. Looking at similar questions on here I found a link: http://support.microsoft.com/kb/131313 I cannot however follow the directions.

The information in the link says to make a DEF file ( I read elsewhere that this needs to be compiled as a DLL with the same name, but not sure what that name is, the same name as the .dll file?). But I do not understand the first direction, to 'Use DUMPBIN /EXPORTS'. I then need to 'stub out' functions, and then something to do with .OBJ files (I do not know what these files are).

Are there any step-by-step directions, similar to the link above, that are easy to follow?

like image 385
hde Avatar asked Feb 20 '12 11:02

hde


People also ask

Does a DLL need a lib file?

A DLL is a library of functions that are shared among other executable programs. Just look in your windows/system32 directory and you will find dozens of them. When your program creates a DLL it also normally creates a lib file so that the application *.exe program can resolve symbols that are declared in the DLL.

Is DLL same as lib?

LIB vs DLL LIB is a static library where functions and procedures can be placed and called as the application is being compiled. A DLL or Dynamic Link Library does the same function but is dynamic in a sense that the application can call these libraries during run-time and not during the compilation.

Can a exe link to DLL and static library at the same time?

Yes, the Core and Utils code will be duplicated. Instead of building them as static libs you can build them as dlls and use anywhere.

How do I create a DLL and lib in Visual Studio?

To create a DLL project in Visual Studio 2019On the menu bar, choose File > New > Project to open the Create a New Project dialog box. At the top of the dialog, set Language to C++, set Platform to Windows, and set Project type to Library.


1 Answers

You're going to need Microsoft Visual C++ 2010 Express (or any other source of MSVC command line tools), and your DLL.

Steps:

  1. dumpbin /EXPORTS yourfile.dll > yourfile.exports
  2. Paste the names of the needed functions from yourfile.exports into a new yourfile.def file. Add a line with the word EXPORTS at the top of this file.
  3. Run the following commands from VC\bin directory (the one where lib.exe and other compile tools reside).

 

 vcvars32.bat   lib /def:yourfile.def /out:yourfile.lib 

or for x64 builds

 lib /def:yourfile.def /machine:x64 /out:yourfile64.lib 

You should get two files generated: yourfile.lib and yourfile.exp

like image 135
Sany Liew Avatar answered Oct 09 '22 03:10

Sany Liew