This commit was manufactured by cvs2svn to create tag 'r241c1'.
[python/dscho.git] / PC / example_nt / readme.txt
blob65665badfff2acee9898a246cbb5797710015dec
1 Example Python extension for Windows NT\r
2 =======================================\r
3 \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 7.1.  It has been tested with VC++ 7.1 on \r
7 Python 2.4.  You can also use earlier versions of VC to build Python \r
8 extensions, but the sample VC project file (example.dsw in this directory) \r
9 is in VC 7.1 format. Notice that you need to use the same compiler version\r
10 that was used to build Python itself.\r
12 COPY THIS DIRECTORY!\r
13 --------------------\r
14 This "example_nt" directory is a subdirectory of the PC directory, in order\r
15 to keep all the PC-specific files under the same directory.  However, the\r
16 example_nt directory can't actually be used from this location.  You first\r
17 need to copy or move it up one level, so that example_nt is a direct\r
18 sibling of the PC\ and Include\ directories.  Do all your work from within\r
19 this new location -- sorry, but you'll be sorry if you don't.\r
21 OPEN THE PROJECT\r
22 ----------------\r
23 From VC 7.1, use the\r
24     File -> Open Solution...\r
25 dialog (*not* the "File -> Open..." dialog!).  Navigate to and select the\r
26 file "example.sln", in the *copy* of the example_nt directory you made\r
27 above.\r
28 Click Open.\r
30 BUILD THE EXAMPLE DLL\r
31 ---------------------\r
32 In order to check that everything is set up right, try building:\r
34 1. Select a configuration.  This step is optional.  Do\r
35        Build -> Configuration Manager... -> Active Solution Configuration\r
36    and select either "Release" or "Debug".\r
37    If you skip this step, you'll use the Debug configuration by default.\r
39 2. Build the DLL.  Do\r
40        Build -> Build Solution\r
41    This creates all intermediate and result files in a subdirectory which\r
42    is called either Debug or Release, depending on which configuration you\r
43    picked in the preceding step.\r
45 TESTING THE DEBUG-MODE DLL\r
46 --------------------------\r
47 Once the Debug build has succeeded, bring up a DOS box, and cd to\r
48 example_nt\Debug.  You should now be able to repeat the following session\r
49 ("C>" is the DOS prompt, ">>>" is the Python prompt) (note that various\r
50 debug output from Python may not match this screen dump exactly):\r
52     C>..\..\PCbuild\python_d\r
53     Adding parser accelerators ...\r
54     Done.\r
55     Python 2.2c1+ (#28, Dec 14 2001, 18:06:39) [MSC 32 bit (Intel)] on win32\r
56     Type "help", "copyright", "credits" or "license" for more information.\r
57     >>> import example\r
58     [7052 refs]\r
59     >>> example.foo()\r
60     Hello, world\r
61     [7052 refs]\r
62     >>>\r
64 TESTING THE RELEASE-MODE DLL\r
65 ----------------------------\r
66 Once the Release build has succeeded, bring up a DOS box, and cd to\r
67 example_nt\Release.  You should now be able to repeat the following session\r
68 ("C>" is the DOS prompt, ">>>" is the Python prompt):\r
70     C>..\..\PCbuild\python\r
71     Python 2.2c1+ (#28, Dec 14 2001, 18:06:04) [MSC 32 bit (Intel)] on win32\r
72     Type "help", "copyright", "credits" or "license" for more information.\r
73     >>> import example\r
74     >>> example.foo()\r
75     Hello, world\r
76     >>>\r
78 Congratulations!  You've successfully built your first Python extension\r
79 module.\r
81 CREATING YOUR OWN PROJECT\r
82 -------------------------\r
83 Choose a name ("spam" is always a winner :-) and create a directory for\r
84 it.  Copy your C sources into it.  Note that the module source file name\r
85 does not necessarily have to match the module name, but the "init" function\r
86 name should match the module name -- i.e. you can only import a module\r
87 "spam" if its init function is called "initspam()", and it should call\r
88 Py_InitModule with the string "spam" as its first argument (use the minimal\r
89 example.c in this directory as a guide).  By convention, it lives in a file\r
90 called "spam.c" or "spammodule.c".  The output file should be called\r
91 "spam.dll" or "spam.pyd" (the latter is supported to avoid confusion with a\r
92 system library "spam.dll" to which your module could be a Python interface)\r
93 in Release mode, or spam_d.dll or spam_d.pyd in Debug mode.\r
95 Now your options are:\r
97 1) Copy example.sln and example.vcproj, rename them to spam.*, and edit them\r
98 by hand.\r
100 or\r
102 2) Create a brand new project; instructions are below.\r
104 In either case, copy example_nt\example.def to spam\spam.def, and edit the\r
105 new spam.def so its second line contains the string "initspam".  If you\r
106 created a new project yourself, add the file spam.def to the project now.\r
107 (This is an annoying little file with only two lines.  An alternative\r
108 approach is to forget about the .def file, and add the option\r
109 "/export:initspam" somewhere to the Link settings, by manually editing the\r
110 "Project -> Properties -> Linker -> Command Line -> Additional Options" \r
111 box).\r
113 You are now all set to build your extension, unless it requires other\r
114 external libraries, include files, etc.  See Python's Extending and\r
115 Embedding manual for instructions on how to write an extension.\r
118 CREATING A BRAND NEW PROJECT\r
119 ----------------------------\r
120 Use the\r
121     File -> New -> Project...\r
122 dialog to create a new Project Workspace.  Select "Visual C++ Projects/Win32/\r
123 Win32 Project", enter the name ("spam"), and make sure the "Location" is \r
124 set to parent of the spam directory you have created (which should be a direct \r
125 subdirectory of the Python build tree, a sibling of Include and PC).  \r
126 In "Application Settings", select "DLL", and "Empty Project".  Click OK.\r
128 You should now create the file spam.def as instructed in the previous\r
129 section. Add the source files (including the .def file) to the project, \r
130 using "Project", "Add Existing Item".\r
132 Now open the\r
133     Project -> spam properties...\r
134 dialog.  (Impressive, isn't it? :-) You only need to change a few\r
135 settings.  Make sure "All Configurations" is selected from the "Settings\r
136 for:" dropdown list.  Select the "C/C++" tab.  Choose the "General"\r
137 category in the popup menu at the top.  Type the following text in the\r
138 entry box labeled "Addditional Include Directories:"\r
140     ..\Include,..\PC\r
142 Then, choose the "General" category in the "Linker" tab, and enter\r
143     ..\PCbuild\r
144 in the "Additional library Directories" box.\r
146 Now you need to add some mode-specific settings (select "Accept"\r
147 when asked to confirm your changes):\r
149 Select "Release" in the "Configuration" dropdown list.  Click the\r
150 "Link" tab, choose the "Input" Category, and append "python24.lib" to the\r
151 list in the "Additional Dependencies" box.\r
153 Select "Debug" in the "Settings for:" dropdown list, and append\r
154 "python24_d.lib" to the list in the Additional Dependencies" box.  Then\r
155 click on the C/C++ tab, select "Code Generation", and select \r
156 "Multi-threaded Debug DLL" from the "Runtime library" dropdown list.\r
158 Select "Release" again from the "Settings for:" dropdown list.\r
159 Select "Multi-threaded DLL" from the "Use run-time library:" dropdown list.\r
161 That's all <wink>.\r