GNU Info

Info Node: (python2.1-ext.info)Using DLLs in Practice

(python2.1-ext.info)Using DLLs in Practice


Prev: Differences Between UNIX and Windows Up: Building C and C++ Extensions on Windows
Enter node , (file) or (file)node

Using DLLs in Practice
======================

This manual section was written by Chris Phoenix <cphoenix@best.com>.
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 `python15.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/python15.lib
     cl /LD /I/python/include ni.c spam.lib ../libs/python15.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 `python15.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.


automatically generated by info2www version 1.2.2.9