tags:

views:

76

answers:

3

What is the difference between *.a and *.dll on Windows? From what I understand one can package all the *.o files into a *.a, which is a distributable that other application can use, on Linux.

But what are the difference between *.a and *.dll? Are they interchangeable? If my application needs to link to *.a, can I link it to *.dll as a substitute?

+2  A: 

Aside: There is no defined *.a format with plain Windows development tools, unless you use a Linux-based tool chain. You're presumably referring to a static library, aka .lib in Windows.

A DLL is the equivalent of a shared library (*.so) on Unix and no, you normally can't link to a shared library/dll if the linker expects you to link against a static library.

Timo Geusch
shared object libraries have a `*.so` extension under Linux, maybe worth also to tell even if that are not really breaking news :-P
jdehaan
But you can extract the static library from the dll, and then link to the extracted library.
erikkallen
A: 

Under Linux with gcc you will see two kind of files the archives *.a (used to provide a set of functions to link in statically) and *.so, so called shared object library (to link dynamically). Their equivalent under windows for most compilers are *.lib and *.dll.

So *.a and *.dll are not interchangeable at all. Moreover you have under windows the dilemma that a *.lib can be used for both linking statically and dynamically (with fixed addresses). Another way is to bind fully dynamically with GetProcAddress but that has to overhead of creating a wrapper, might be what you need if you want to make the dlls work for different versions.

You may recognize the static libs at their size, they are huge in comparison to the libs used to link dynamically. In my projects I really often go the way with GetProcAddress as I like the ability to just drop in the fresh new DLLs for older applications without linking everything again.

jdehaan
There is no reason a static library must be larger than a dynamic one. An *application* that uses static libraries will typically be larger though.
anon
I meant the lib file for dll linking is merely containing only the addresses of the functions, the static lib however contains all the stuff. It was maybe not clear that I was comparing the lib files and not the dll to the corresponding lib. Regards, Jaap
jdehaan
A: 

Seeing that *.a are Linux static libraries, they are not at all interchangeable with windows .dll (dynamic linking libraries),as they have entirely different formats. If your application needs to link to an .a that you created, you will need to recompile the source code that generated your linux static library (if possible) into a windows static library (.lib), and compile your code against that.

futureelite7