Main BLOGGER
Google
WWW THIS BLOG
Thursday, June 23, 2005
 
dynamic link in windows and linux
Quoted from http://cphoenix.best.vwh.net/winvunix.html

In Unix,
(1) .a :contains code from several object files (.o).
(2) .so :contains code to be used by the program, and also the names of functions and data that it expects to find in the program. When the file is joined to the program, all references to those functions and data in the file's code are changed to point to the actual locations in the program where the functions and data are placed in memory. This is basically a link operation.

In Windows, there are three types of library, a static library and an import library (both called .lib) and a dynamic-link library(.dll).

(1) .dll file has a lookup table. An access from DLL to functions or data in the program goes through a lookup table. So the DLL code does not have to be fixed up at runtime to refer to the program's memory; instead, the code in DLL already uses the DLL's lookup table, and the lookup table is modified at runtime to point to the functions and data.

(2) A static library is like a Unix .a file; it contains code to be included as necessary.

(3) An import library is basically used only to reassure the linker that a certain identifier is legal, and will be present in the program when the .dll is loaded. So the linker uses the information from the import library to build the lookup table for using identifiers that aren't included in the .dll. When an application or a .dll is linked, an import library may be generated, which will need to be used for all future .dll's that depend on the symbols in the application or .dll.

I call the following scenario The diamond puzzle:
A program Aa needs two dynamic linked libraries, say, Db and Dc. These two libraries share a common static library Sd. In linux, this situaion causes Sd to be linked into Aa twice which will lead to name confliction error. While in windows, this puzzle could be solve by import library since the code in Sd is not copied into Db or Dc. Only the reference information is copied.



<< Home

Powered by Blogger

Google
WWW THIS BLOG