Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="ext.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="ext.html" title='Extending and Embedding the Python Interpreter' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='last' href='about.html' title='About this document...' /> | |
10 | <link rel='help' href='about.html' title='About this document...' /> | |
11 | <link rel="next" href="win-dlls.html" /> | |
12 | <link rel="prev" href="win-cookbook.html" /> | |
13 | <link rel="parent" href="building-on-windows.html" /> | |
14 | <link rel="next" href="win-dlls.html" /> | |
15 | <meta name='aesop' content='information' /> | |
16 | <title>4.2 Differences Between Unix and Windows </title> | |
17 | </head> | |
18 | <body> | |
19 | <DIV CLASS="navigation"> | |
20 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
21 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
22 | <tr> | |
23 | <td class='online-navigation'><a rel="prev" title="4.1 A Cookbook Approach" | |
24 | href="win-cookbook.html"><img src='../icons/previous.png' | |
25 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
26 | <td class='online-navigation'><a rel="parent" title="4. Building C and" | |
27 | href="building-on-windows.html"><img src='../icons/up.png' | |
28 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
29 | <td class='online-navigation'><a rel="next" title="4.3 Using DLLs in" | |
30 | href="win-dlls.html"><img src='../icons/next.png' | |
31 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
32 | <td align="center" width="100%">Extending and Embedding the Python Interpreter</td> | |
33 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
34 | href="contents.html"><img src='../icons/contents.png' | |
35 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
36 | <td class='online-navigation'><img src='../icons/blank.png' | |
37 | border='0' height='32' alt='' width='32' /></td> | |
38 | <td class='online-navigation'><img src='../icons/blank.png' | |
39 | border='0' height='32' alt='' width='32' /></td> | |
40 | </tr></table> | |
41 | <div class='online-navigation'> | |
42 | <b class="navlabel">Previous:</b> | |
43 | <a class="sectref" rel="prev" href="win-cookbook.html">4.1 A Cookbook Approach</A> | |
44 | <b class="navlabel">Up:</b> | |
45 | <a class="sectref" rel="parent" href="building-on-windows.html">4. Building C and</A> | |
46 | <b class="navlabel">Next:</b> | |
47 | <a class="sectref" rel="next" href="win-dlls.html">4.3 Using DLLs in</A> | |
48 | </div> | |
49 | <hr /></div> | |
50 | </DIV> | |
51 | <!--End of Navigation Panel--> | |
52 | ||
53 | <H1><A NAME="SECTION006200000000000000000"></A><A NAME="dynamic-linking"></A> | |
54 | <BR> | |
55 | 4.2 Differences Between <span class="Unix">Unix</span> and Windows | |
56 | ||
57 | </H1> | |
58 | ||
59 | <P> | |
60 | <span class="Unix">Unix</span> and Windows use completely different paradigms for run-time | |
61 | loading of code. Before you try to build a module that can be | |
62 | dynamically loaded, be aware of how your system works. | |
63 | ||
64 | <P> | |
65 | In <span class="Unix">Unix</span>, a shared object (<span class="file">.so</span>) file contains code to be used by the | |
66 | program, and also the names of functions and data that it expects to | |
67 | find in the program. When the file is joined to the program, all | |
68 | references to those functions and data in the file's code are changed | |
69 | to point to the actual locations in the program where the functions | |
70 | and data are placed in memory. This is basically a link operation. | |
71 | ||
72 | <P> | |
73 | In Windows, a dynamic-link library (<span class="file">.dll</span>) file has no dangling | |
74 | references. Instead, an access to functions or data goes through a | |
75 | lookup table. So the DLL code does not have to be fixed up at runtime | |
76 | to refer to the program's memory; instead, the code already uses the | |
77 | DLL's lookup table, and the lookup table is modified at runtime to | |
78 | point to the functions and data. | |
79 | ||
80 | <P> | |
81 | In <span class="Unix">Unix</span>, there is only one type of library file (<span class="file">.a</span>) which | |
82 | contains code from several object files (<span class="file">.o</span>). During the link | |
83 | step to create a shared object file (<span class="file">.so</span>), the linker may find | |
84 | that it doesn't know where an identifier is defined. The linker will | |
85 | look for it in the object files in the libraries; if it finds it, it | |
86 | will include all the code from that object file. | |
87 | ||
88 | <P> | |
89 | In Windows, there are two types of library, a static library and an | |
90 | import library (both called <span class="file">.lib</span>). A static library is like a | |
91 | <span class="Unix">Unix</span> <span class="file">.a</span> file; it contains code to be included as necessary. | |
92 | An import library is basically used only to reassure the linker that a | |
93 | certain identifier is legal, and will be present in the program when | |
94 | the DLL is loaded. So the linker uses the information from the | |
95 | import library to build the lookup table for using identifiers that | |
96 | are not included in the DLL. When an application or a DLL is linked, | |
97 | an import library may be generated, which will need to be used for all | |
98 | future DLLs that depend on the symbols in the application or DLL. | |
99 | ||
100 | <P> | |
101 | Suppose you are building two dynamic-load modules, B and C, which should | |
102 | share another block of code A. On <span class="Unix">Unix</span>, you would <em>not</em> pass | |
103 | <span class="file">A.a</span> to the linker for <span class="file">B.so</span> and <span class="file">C.so</span>; that would | |
104 | cause it to be included twice, so that B and C would each have their | |
105 | own copy. In Windows, building <span class="file">A.dll</span> will also build | |
106 | <span class="file">A.lib</span>. You <em>do</em> pass <span class="file">A.lib</span> to the linker for B and | |
107 | C. <span class="file">A.lib</span> does not contain code; it just contains information | |
108 | which will be used at runtime to access A's code. | |
109 | ||
110 | <P> | |
111 | In Windows, using an import library is sort of like using "<tt class="samp">import | |
112 | spam</tt>"; it gives you access to spam's names, but does not create a | |
113 | separate copy. On <span class="Unix">Unix</span>, linking with a library is more like | |
114 | "<tt class="samp">from spam import *</tt>"; it does create a separate copy. | |
115 | ||
116 | <P> | |
117 | ||
118 | <DIV CLASS="navigation"> | |
119 | <div class='online-navigation'> | |
120 | <p></p><hr /> | |
121 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
122 | <tr> | |
123 | <td class='online-navigation'><a rel="prev" title="4.1 A Cookbook Approach" | |
124 | href="win-cookbook.html"><img src='../icons/previous.png' | |
125 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
126 | <td class='online-navigation'><a rel="parent" title="4. Building C and" | |
127 | href="building-on-windows.html"><img src='../icons/up.png' | |
128 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
129 | <td class='online-navigation'><a rel="next" title="4.3 Using DLLs in" | |
130 | href="win-dlls.html"><img src='../icons/next.png' | |
131 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
132 | <td align="center" width="100%">Extending and Embedding the Python Interpreter</td> | |
133 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
134 | href="contents.html"><img src='../icons/contents.png' | |
135 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
136 | <td class='online-navigation'><img src='../icons/blank.png' | |
137 | border='0' height='32' alt='' width='32' /></td> | |
138 | <td class='online-navigation'><img src='../icons/blank.png' | |
139 | border='0' height='32' alt='' width='32' /></td> | |
140 | </tr></table> | |
141 | <div class='online-navigation'> | |
142 | <b class="navlabel">Previous:</b> | |
143 | <a class="sectref" rel="prev" href="win-cookbook.html">4.1 A Cookbook Approach</A> | |
144 | <b class="navlabel">Up:</b> | |
145 | <a class="sectref" rel="parent" href="building-on-windows.html">4. Building C and</A> | |
146 | <b class="navlabel">Next:</b> | |
147 | <a class="sectref" rel="next" href="win-dlls.html">4.3 Using DLLs in</A> | |
148 | </div> | |
149 | </div> | |
150 | <hr /> | |
151 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
152 | </DIV> | |
153 | <!--End of Navigation Panel--> | |
154 | <ADDRESS> | |
155 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
156 | </ADDRESS> | |
157 | </BODY> | |
158 | </HTML> |