1 Example Python extension for Windows NT
\r
2 =======================================
\r
4 This directory contains everything needed (except for the Python
\r
5 distribution!) to build a Python extension module using Microsoft VC++
\r
6 ("Developer Studio") version 6. It has been tested with VC++ 6.0 on Python
\r
7 2.1a1. You can also use earlier versions of VC to build Python extensions,
\r
8 but the sample VC project file (example.dsw in this directory) is in VC 6
\r
11 COPY THIS DIRECTORY!
\r
12 --------------------
\r
13 This "example_nt" directory is a subdirectory of the PC directory, in order
\r
14 to keep all the PC-specific files under the same directory. However, the
\r
15 example_nt directory can't actually be used from this location. You first
\r
16 need to copy or move it up one level, so that example_nt is a direct
\r
17 sibling of the PC\ and Include\ directories. Do all your work from within
\r
18 this new location -- sorry, but you'll be sorry if you don't.
\r
22 From VC 6.x, use the
\r
23 File -> Open Workspace...
\r
24 dialog (*not* the "File -> Open..." dialog!). Navigate to and select the
\r
25 file "example.dsw", in the *copy* of the example_nt directory you made
\r
29 BUILD THE EXAMPLE DLL
\r
30 ---------------------
\r
31 In order to check that everything is set up right, try building:
\r
33 1. Select a configuration. This step is optional. Do
\r
34 Build -> Select Active Configuration...
\r
35 and select either "example - Win32 Release" or "example - Win32 Debug".
\r
36 If you skip this step, you'll use the Debug configuration by default.
\r
38 2. Build the DLL. Do
\r
39 Build -> Build example_d.dll
\r
41 Build -> Build example.dll
\r
43 This creates all intermediate and result files in a subdirectory which
\r
44 is called either Debug or Release, depending on which configuration you
\r
45 picked in the preceding step.
\r
47 TESTING THE DEBUG-MODE DLL
\r
48 --------------------------
\r
49 Once the Debug build has succeeded, bring up a DOS box, and cd to
\r
50 example_nt\Debug. You should now be able to repeat the following session
\r
51 ("C>" is the DOS prompt, ">>>" is the Python prompt) (note that various
\r
52 debug output from Python may not match this screen dump exactly):
\r
54 C>..\..\PCbuild\python_d
\r
55 Adding parser accelerators ...
\r
57 Python 2.1a1 (#9, Jan 17 2001, 23:26:37) [MSC 32 bit (Intel)] on win32
\r
58 Type "copyright", "credits" or "license" for more information.
\r
66 TESTING THE RELEASE-MODE DLL
\r
67 ----------------------------
\r
68 Once the Release build has succeeded, bring up a DOS box, and cd to
\r
69 example_nt\Release. You should now be able to repeat the following session
\r
70 ("C>" is the DOS prompt, ">>>" is the Python prompt):
\r
72 C>..\..\PCbuild\python
\r
73 Python 2.1a1 (#9, Jan 17 2001, 23:26:37) [MSC 32 bit (Intel)] on win32
\r
74 Type "copyright", "credits" or "license" for more information.
\r
80 Congratulations! You've successfully built your first Python extension
\r
83 CREATING YOUR OWN PROJECT
\r
84 -------------------------
\r
85 Choose a name ("spam" is always a winner :-) and create a directory for
\r
86 it. Copy your C sources into it. Note that the module source file name
\r
87 does not necessarily have to match the module name, but the "init" function
\r
88 name should match the module name -- i.e. you can only import a module
\r
89 "spam" if its init function is called "initspam()", and it should call
\r
90 Py_InitModule with the string "spam" as its first argument (use the minimal
\r
91 example.c in this directory as a guide). By convention, it lives in a file
\r
92 called "spam.c" or "spammodule.c". The output file should be called
\r
93 "spam.dll" or "spam.pyd" (the latter is supported to avoid confusion with a
\r
94 system library "spam.dll" to which your module could be a Python interface)
\r
95 in Release mode, or spam_d.dll or spam_d.pyd in Debug mode.
\r
97 Now your options are:
\r
99 1) Copy example.dsw and example.dsp, rename them to spam.*, and edit them
\r
104 2) Create a brand new project; instructions are below.
\r
106 In either case, copy example_nt\example.def to spam\spam.def, and edit the
\r
107 new spam.def so its second line contains the string "initspam". If you
\r
108 created a new project yourself, add the file spam.def to the project now.
\r
109 (This is an annoying little file with only two lines. An alternative
\r
110 approach is to forget about the .def file, and add the option
\r
111 "/export:initspam" somewhere to the Link settings, by manually editing the
\r
112 "Project Options" box).
\r
114 You are now all set to build your extension, unless it requires other
\r
115 external libraries, include files, etc. See Python's Extending and
\r
116 Embedding manual for instructions on how to write an extension.
\r
119 CREATING A BRAND NEW PROJECT
\r
120 ----------------------------
\r
122 File -> New... -> Projects
\r
123 dialog to create a new Project Workspace. Select "Win32 Dynamic-Link
\r
124 Library", enter the name ("spam"), and make sure the "Location" is set to
\r
125 the spam directory you have created (which should be a direct subdirectory
\r
126 of the Python build tree, a sibling of Include and PC). Select Win32 as the
\r
127 platform (in my version, this is the only choice). Make sure the "Create
\r
128 new workspace" radio button is selected. Click OK.
\r
131 Project -> Settings...
\r
132 dialog. (Impressive, isn't it? :-) You only need to change a few
\r
133 settings. Make sure "All Configurations" is selected from the "Settings
\r
134 for:" dropdown list. Select the "C/C++" tab. Choose the "Preprocessor"
\r
135 category in the popup menu at the top. Type the following text in the
\r
136 entry box labeled "Addditional include directories:"
\r
140 Then, choose the "Input" category in the Link tab, and enter
\r
142 in the "Additional library path:" box.
\r
144 Now you need to add some mode-specific settings:
\r
146 Select "Win32 Release" in the "Settings for:" dropdown list. Click the
\r
147 "Link" tab, choose the "Input" Category, and append "python21.lib" to the
\r
148 list in the "Object/library modules:" box.
\r
150 Select "Win32 Debug" in the "Settings for:" dropdown list, and append
\r
151 "python21_d.lib" to the list in the "Object/library modules:" box. Then
\r
152 click on the C/C++ tab, select "Code Generation" from the "Category:"
\r
153 dropdown list, and select "Debug Multithreaded DLL" from the "Use run-time
\r
154 library:" dropdown list.
\r
156 Select "Win32 Release" again from the "Settings for:" dropdown list.
\r
157 Select "Multithreaded DLL" from the "Use run-time library:" dropdown list.
\r
161 You should now create the file spam.def as instructed in the previous
\r
162 section. Then chose the
\r
163 Insert -> Files into Project...
\r
164 dialog. Set the pattern to *.* and select both spam.c and spam.def and
\r
165 click OK. (Inserting them one by one is fine too.)
\r