tags:

views:

53

answers:

3

I just downloaded curl and managed to build a programe with it.

What I don't understand is why it requires both curllib.lib and curllib.dll ?

In my opinion either curllib.lib or curllib.dll should be enough, why both?

Also I've searched through the source but doesn't find anywhere it uses dlopen to load curllib.dll, so why is curllib.dll required to run?

+2  A: 

curllib.lib is the import library. It contains stubs for all the functions whose actual code is in the DLL, and it contains code to load the DLL. The .lib is automatically generated by the build system (e.g. Visual Studio), which is why you won't find any references in the code. You will find, however, some directives that tell the compiler/linker to export certain functions:

  • __declspec(dllexport) on a function declaration will export that function. This is convenient, but Microsoft-specific. For example:

    void __declspec(dllexport) foobar(int qux);

    More information here.

  • Alternatively, a .def file can be used, that explicitly lists all functions that are exported. For example:

    LIBRARY MYFOO
    EXPORTS
    foobar @1

    More information here.

You can do without the .lib if you really want to, but you'll have to manually use LoadLibrary, GetProcAddress and friends to call the function in the DLL.

Thomas
Can you list a few `directives that tell the compiler/linker to export certain functions` ?
ieplugin
See my edit. :)
Thomas
Will the exported `dll` be automatically named according to the `lib`? Say the dll for `curllib.lib` will be `curllib.dll`? I ask this because I don't find any explicit reference to `curllib.dll` in the possible derectives..
ieplugin
The name will be the same. By default, Visual C++ will give both the `.lib` and the `.dll` the same name as the project. This can be changed in the project settings. I don't know whether the name of the `.lib` and the `.dll` can be changed independently, though -- but that will only lead to confusion anyway.
Thomas
A: 

When you use a DLL on Windows, you typically use it with a .lib file that tells the linker enough to be able to create an executable. The executable then uses the .dll file at run time.

OTOH, dlopen is a UNIX/Linux/POSIX kind of thing -- the equivalent on Windows would be LoadLibrary. You'd normally use dlopen with a .so file.

Jerry Coffin
+1  A: 

The .dll is required to run. The .lib exists so the linker can resolve the ordinals and addresses from function names, and is only required at link time.

Other systems (such as Linux) maintain full linkage information in shared libraries and would not require this.

Yann Ramin