How to make a .lib file when there is a .dll file and a header file

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

I am researching on the Internet and found that I need to create a .lib file. If you look at such questions, here I found a link: http://support.microsoft.com/kb/131313 However, I can not follow the directions.

The information in the link indicates the creation of a DEF file (I read elsewhere that it needs to be compiled as a DLL with the same name, but not sure if it is a name with the same name as the DLL file?), But I do not understand first direction: "Use DUMPBIN / EXPORTS". Then I need to "drown out" the functions, and then do something with the .OBJ files (I don’t know what these files are).

Are there any step-by-step instructions similar to the links above that are easy to track?

+38
c ++ function dll header
Feb 20 '12 at 11:20
source share
3 answers

You will need Microsoft Visual C ++ 2010 Express (or any other source of MSVC command-line tools) and your DLL.

Steps:

  • dumpbin /EXPORTS yourfile.dll > yourfile.exports
  • Paste the names of the required functions from yourfile.exports into the new yourfile.def file. Add a line with the word EXPORTS at the top of this file.
  • Run the following commands from the VC\bin (the one where lib.exe and other compilation tools are).

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

You must create two files: yourfile.lib and yourfile.exp

+53
Apr 21 '13 at 3:09 on
source share

You can use the Digital Mars IMPLIB tool . It can create a lib file using only a DLL, without the need for a .def file.

Download link http://ftp.digitalmars.com/bup.zip .

Command line:

 implib.exe /s mydll.lib mydll.dll 
+16
Feb 20 2018-12-12T00:
source share

Instead of creating a .def, you can create a .lib file from a DLL file by exporting the functions / classes defined in the .dll file, __declspec (dllexport), which were specified in the application code.

For example (pseudo-code)

The PROJECT for creating the X.dll file (let's say X is the name of the dll):

hijras:

 // Function declaration __declspec(dllexport) void foo(void); 

a.cpp:

 // Function definition #include <Ah> void foo(void) { ; // definition } 

If you create the above dll project in Visual Studio, then the compiler will generate X.dll as well as X.lib [which exported the foo function by __declspec (dllexport)].

App.cpp:

 // Load time dynamic linking: // Application should include X.lib (not X.dll) in the project setting #include <Ah> int main() { foo(); return 0; } 

For further study, please refer to the following links for a better understanding:

http://www.codeproject.com/Articles/28969/HowTo-Export-C-classes-from-a-DLL#CppMatureApproach

http://msdn.microsoft.com/en-us/library/ms686923(v=vs.85).aspx

-3
Sep 03 '13 at 16:18
source share



All Articles