In Windows, using an import library is sort of like using$_{import spam}$; it gives you access to spam’s names, but does not create a separate copy. On Unix, linking with a library is more like from spam import * ; it does create a separate copy. 

## 2.5.3 Using DLLs in Practice 

Windows Python is built in Microsoft Visual C++; using other compilers may or may not work (though Borland seems to). The rest of this section is MSVC++ specific. 

When creating DLLs in Windows, you must pass$_{pythonXY.lib}$to the linker. To build two DLLs, spam and ni (which uses C functions found in spam), you could use these commands: 

cl/LD /I/python/include spam.c .. /libs/pythonXY.lib cl/LD /I/python/include ni.c spam.lib .. /libs/pythonXY.lib 

The first command created three files: spam.obj , spam.dll and$_{spam.lib}$ . Spam.dll does not contain any Python functions (such as$_{PyArg_ParseTuple()}$ ), but it does know how to find the Python code thanks to pythonXY.lib . 

The second command created ni.dll (and .obj and .lib ), which knows how to find the necessary functions from spam, and also from the Python executable. 

Not every identifier is exported to the lookup table. If you want any other modules (including Python) to be able to see your identifiers, you have to say$_{_declspec(dllexport)}$ , as in$_{void _declspec(dllexport)}$ initspam(void) or$_{PyObject _declspec(dllexport) *NiGetSpamData(void)}$ . 

Developer Studio will throw in a lot of import libraries that you do not really need, adding about 100K to your executable. To get rid of them, use the Project Settings dialog, Link tab, to specify ignore default libraries . Add the correct$_{msvcrtxx.lib}$ to the list of libraries. 

