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?
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.
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.
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.
精彩评论