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

2019-01-03 14:42发布

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?

3条回答
别忘想泡老子
2楼-- · 2019-01-03 15:20

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

The download link is http://ftp.digitalmars.com/bup.zip.

The command line is:

implib.exe /s mydll.lib mydll.dll
查看更多
贪生不怕死
3楼-- · 2019-01-03 15:22

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

For example (Pseudo code)

PROJECT for creating X.dll file (say, X is a dll name):

A.h:

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

A.cpp:

// Function definition 
#include <A.h>
void foo(void) {
; // definition
}

If you build the above dll project in Visual Studio then the compiler will generate X.dll and also X.lib [which has exported function foo by __declspec(dllexport) ].

App.cpp:

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

For further study please refer the following links for 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

查看更多
Emotional °昔
4楼-- · 2019-01-03 15:26

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

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

查看更多
登录 后发表回答