2

It's pointed out by this answer:

Failed to link mysql5.1.39\bin\libmySQL.dll

But I don't understand why,.dll is essentially the same as .lib except for there is only one copy of it used by different processes.

Does it have anything to do with the IDE?I'm using visual c++ 2008 express

UPDATE

Anyone know a free tool to convert .dll into .lib in windows?

Community
  • 1
  • 1
Mask
  • 33,129
  • 48
  • 101
  • 125

5 Answers5

5

You are wrong on two counts. Firstly, DLLs and LIBs (static libraries) are very different beasts. The LIB you are talking about (I think) is the export library, which is simply a list of names in the DLL. This library is typically produced when the DLL is compiled and is shipped with the DLL if the DLL is intended to be linked to by other developers.

To use a DLL with a modern IDE (I don't use VS) you typically include the matching .LIB (export library) in the project. At run-time you must make sure the DLL is available to your program - the simplest way to do this is to put the DLL in the same directory as the executable.

And secondly, DLLs can be used with C++.

  • @Neil: He's mixed up between link libraries and full static libraries. “Helpfully” they have the same extension. – Donal Fellows Mar 28 '10 at 10:53
  • All I have by hand is `libmySQL.dll` and no `.lib`,so the only way out seems to be a tool that can convert the dll into lib.Is there a free one that actually works? – Mask Mar 28 '10 at 12:14
  • @Mask: If you don't have an import library (the `.lib` that goes with the DLL), you need to use `LoadLibrary`, `GetProcAddress`, and friends to load the library (http://msdn.microsoft.com/en-us/library/ms684175(VS.85).aspx) and call its interface functions. – James McNellis Mar 28 '10 at 21:39
0

DLL are specific windows executables which load on runtime. Their equivalent in Linux is the *.so .
If you want to understand what's the difference between a DLL and a static lib see here.

Community
  • 1
  • 1
the_drow
  • 18,571
  • 25
  • 126
  • 193
  • Is there a reliable tool to convert dll to lib? – Mask Mar 28 '10 at 10:38
  • 1
    no, they have different entry points. in fact a static lib is static and it's sort of an "attachment" to your main exe, so it's entry point is your exe. The DLL has a separate entry point. – the_drow Mar 28 '10 at 10:42
0

Main reason has probably something to do with dll-file being an output of the linker (link.exe). This command line utility doesnt know how to read dlls, only how to write them.

Actually sometimes .lib-files contain more than a list of functions. For example libpng.lib works as a standalone file, without any dll file.

AareP
  • 2,355
  • 3
  • 21
  • 28
  • There are at least two types of .lib files export libraries and static libraries. –  Mar 28 '10 at 10:51
0

In order to use a DLL in C/C++ you need to link with what is called an import lib. This is a small .lib that contains the names/ordinals the DLL exports in a format that the linker understands. Once this has been linked in, the resulting binary will be able to use the DLL. If you do not have the appropriate import lib, your C/C++ compiler should come with a tool to generate one from the DLL.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358
0

You can use the following analogy to understand the difference between a dll and a lib file.

the dll is like the source .cpp file while the lib is the header .h file.

While this is not exactly true, the DLL holds the executable code while the LIB file tells the linker how to glue the code together.

It is also possible (in some cases) to generate the lib from the dll. Basically, all you need to know to call a function is the function entry point in the dll, the number of parameters and the size of each parameters. Sending relevant information is then your own problem.

Eric
  • 19,525
  • 19
  • 84
  • 147
  • Someone has asked about this but seems there isn't a free and working tool yet:http://stackoverflow.com/questions/1536557/converting-a-windows-dll-to-lib-for-c-visual-studio-2008 – Mask Mar 28 '10 at 12:09