Tuesday, June 2, 2009

About Libraries (dll, lib, so...)?

At first, pardons for the subject. I know this is not fully related to Python, but I did not mean to have a Pythonic-only weblog. I started to found a technical weblog & since I was (am) fond of python, I chose the name.
Libraries are the most usual facts programmers face everywhere.By everywhere, I mean in every OS, every language and with every level of knowledge.I decided to write a brief but useful article about types of libraries here after a friend of mine asked about 'dll's.
in general, libraries are packages of code (usually compiled) for being used more and more. That is, libraries are the most common way of code 'reusability'.
Libraries are of 2 types in general: Static & Dynamic.
Static libraries are familiar for most C++ developers. Files with .lib extension are C static libraries. They are embedded to the executable file when compiling for deployment. So end user will never feel them from close.
Dynamic libraries has the main difference of being able to load and unload dynamically when running the executable. They usually do not attach or embed to executable file. Instead they reside on a special OS directory or beside the executable directory to be used just when they are needed. Although they can still be used as a static library.
dll means Dynamic Load Library.You can guess what dll is now. .so files are the unix variant and .dynlib Mac's one.
We have 3 different types of dll in Windows.
1. Native dlls which contain fully compiled code with OS (Windows) API calls.They usually export functions (procedure, subroutine..)
2. COM or ActiveX dlls that are OOP and support Classes instead f just Functions. They are fully compiled but a bit slower because of instantiating and destroying objects.
3. .NET dlls that are .NET assemblies (collection of classes) compiled as byte code (not native code). They also contain classes (OOP)
How you can distinguish them? Just use Microsoft Dependency walker on Windows. If the dll has exported some functions it may be native one. If it exports DllregisterServer, DllUnRegisterServer and about 3 other functions this is a COM (ActiveX) dll.
If it does not export anything, just use .NET Reflector to get the .NET class list inside the assembly.