blob: cf6ab7f00c2efdb6babf9fb3f6f18abe299df9c9 [file] [log] [blame]
Christian Heimese8954f82007-11-22 11:21:16 +00001Building Python using VC++ 9.0
2------------------------------
Christian Heimesd9fbab22008-01-02 17:43:40 +00003
Zachary Waree0afd8e2013-11-03 21:43:33 -06004This directory is used to build Python for Win32 and x64 platforms, e.g.
Trent Nelsondbc114a2008-04-02 15:01:00 +00005Windows 2000, XP, Vista and Windows Server 2008. In order to build 32-bit
6debug and release executables, Microsoft Visual C++ 2008 Express Edition is
7required at the very least. In order to build 64-bit debug and release
8executables, Visual Studio 2008 Standard Edition is required at the very
9least. In order to build all of the above, as well as generate release builds
10that make use of Profile Guided Optimisation (PG0), Visual Studio 2008
11Professional Edition is required at the very least. The official Python
12releases are built with this version of Visual Studio.
13
14For other Windows platforms and compilers, see ../PC/readme.txt.
Christian Heimese8954f82007-11-22 11:21:16 +000015
Christian Heimes8b011402007-11-27 21:28:40 +000016All you need to do is open the workspace "pcbuild.sln" in Visual Studio,
17select the desired combination of configuration and platform and eventually
18build the solution. Unless you are going to debug a problem in the core or
19you are going to create an optimized build you want to select "Release" as
20configuration.
Christian Heimese8954f82007-11-22 11:21:16 +000021
Christian Heimes3adfe9a2007-12-31 15:18:55 +000022The PCbuild directory is compatible with all versions of Visual Studio from
Christian Heimes8b011402007-11-27 21:28:40 +000023VS C++ Express Edition over the standard edition up to the professional
Georg Brandl73ac29e2008-09-21 07:17:00 +000024edition. However the express edition does not support features like solution
Christian Heimes8b011402007-11-27 21:28:40 +000025folders or profile guided optimization (PGO). The missing bits and pieces
26won't stop you from building Python.
Christian Heimese8954f82007-11-22 11:21:16 +000027
Christian Heimes8b011402007-11-27 21:28:40 +000028The solution is configured to build the projects in the correct order. "Build
Christian Heimes95d64472008-02-09 19:55:22 +000029Solution" or F7 takes care of dependencies except for x64 builds. To make
Zachary Waree0afd8e2013-11-03 21:43:33 -060030cross compiling x64 builds on a 32bit OS possible the x64 builds require a
Christian Heimes8b011402007-11-27 21:28:40 +00003132bit version of Python.
Christian Heimese8954f82007-11-22 11:21:16 +000032
Christian Heimes3971f6b2007-11-30 19:18:08 +000033NOTE:
34 You probably don't want to build most of the other subprojects, unless
Christian Heimes8b011402007-11-27 21:28:40 +000035 you're building an entire Python distribution from scratch, or
36 specifically making changes to the subsystems they implement, or are
37 running a Python core buildbot test slave; see SUBPROJECTS below)
Christian Heimese8954f82007-11-22 11:21:16 +000038
39When using the Debug setting, the output files have a _d added to
Zachary Waree0afd8e2013-11-03 21:43:33 -060040their name: python27_d.dll, python_d.exe, parser_d.pyd, and so on. Both
Christian Heimes95d64472008-02-09 19:55:22 +000041the build and rt batch files accept a -d option for debug builds.
Christian Heimese8954f82007-11-22 11:21:16 +000042
Christian Heimes3adfe9a2007-12-31 15:18:55 +000043The 32bit builds end up in the solution folder PCbuild while the x64 builds
Christian Heimes8b011402007-11-27 21:28:40 +000044land in the amd64 subfolder. The PGI and PGO builds for profile guided
45optimization end up in their own folders, too.
46
Christian Heimesd9fbab22008-01-02 17:43:40 +000047Legacy support
48--------------
49
Zachary Waree0afd8e2013-11-03 21:43:33 -060050You can find build directories for older versions of Visual Studio and
Christian Heimesd9fbab22008-01-02 17:43:40 +000051Visual C++ in the PC directory. The legacy build directories are no longer
52actively maintained and may not work out of the box.
53
54PC/VC6/
55 Visual C++ 6.0
56PC/VS7.1/
57 Visual Studio 2003 (7.1)
Hirokazu Yamamoto26236882010-10-08 10:22:55 +000058PC/VS8.0/
Christian Heimesd9fbab22008-01-02 17:43:40 +000059 Visual Studio 2005 (8.0)
60
61
62C RUNTIME
63---------
64
65Visual Studio 2008 uses version 9 of the C runtime (MSVCRT9). The executables
66are linked to a CRT "side by side" assembly which must be present on the target
Zachary Waree0afd8e2013-11-03 21:43:33 -060067machine. This is available under the VC/Redist folder of your visual studio
Christian Heimesd9fbab22008-01-02 17:43:40 +000068distribution. On XP and later operating systems that support
Trent Nelsondbc114a2008-04-02 15:01:00 +000069side-by-side assemblies it is not enough to have the msvcrt90.dll present,
Christian Heimesd9fbab22008-01-02 17:43:40 +000070it has to be there as a whole assembly, that is, a folder with the .dll
71and a .manifest. Also, a check is made for the correct version.
72Therefore, one should distribute this assembly with the dlls, and keep
73it in the same directory. For compatibility with older systems, one should
74also set the PATH to this directory so that the dll can be found.
75For more info, see the Readme in the VC/Redist folder.
76
Christian Heimese8954f82007-11-22 11:21:16 +000077SUBPROJECTS
78-----------
79These subprojects should build out of the box. Subprojects other than the
80main ones (pythoncore, python, pythonw) generally build a DLL (renamed to
81.pyd) from a specific module so that users don't have to load the code
82supporting that module unless they import the module.
83
84pythoncore
85 .dll and .lib
86python
87 .exe
88pythonw
89 pythonw.exe, a variant of python.exe that doesn't pop up a DOS box
90_socket
91 socketmodule.c
92_testcapi
93 tests of the Python C API, run via Lib/test/test_capi.py, and
94 implemented by module Modules/_testcapimodule.c
95pyexpat
96 Python wrapper for accelerated XML parsing, which incorporates stable
97 code from the Expat project: http://sourceforge.net/projects/expat/
98select
99 selectmodule.c
100unicodedata
101 large tables of Unicode data
102winsound
103 play sounds (typically .wav files) under Windows
104
Trent Nelsondbc114a2008-04-02 15:01:00 +0000105Python-controlled subprojects that wrap external projects:
106_bsddb
Georg Brandle4c1f112008-09-21 07:24:11 +0000107 Wraps Berkeley DB 4.7.25, which is currently built by _bsddb.vcproj.
Zachary Waree0afd8e2013-11-03 21:43:33 -0600108 project.
Trent Nelsondbc114a2008-04-02 15:01:00 +0000109_sqlite3
Zachary Waree0afd8e2013-11-03 21:43:33 -0600110 Wraps SQLite 3.6.21, which is currently built by sqlite3.vcproj.
Christian Heimese8954f82007-11-22 11:21:16 +0000111_tkinter
Trent Nelsondbc114a2008-04-02 15:01:00 +0000112 Wraps the Tk windowing system. Unlike _bsddb and _sqlite3, there's no
113 corresponding tcltk.vcproj-type project that builds Tcl/Tk from vcproj's
114 within our pcbuild.sln, which means this module expects to find a
Zachary Ware21a23502014-11-01 22:34:09 -0500115 pre-built Tcl/Tk in either ..\externals\tcltk for 32-bit or
116 ..\externals\tcltk64 for 64-bit (relative to this directory). See below
117 for instructions to build Tcl/Tk.
Christian Heimese8954f82007-11-22 11:21:16 +0000118bz2
119 Python wrapper for the libbz2 compression library. Homepage
120 http://sources.redhat.com/bzip2/
121 Download the source from the python.org copy into the dist
122 directory:
123
Martin v. Löwise7f67b52012-05-14 14:19:09 +0200124 svn export http://svn.python.org/projects/external/bzip2-1.0.6
Christian Heimese8954f82007-11-22 11:21:16 +0000125
Trent Nelsondbc114a2008-04-02 15:01:00 +0000126 ** NOTE: if you use the Tools\buildbot\external(-amd64).bat approach for
127 obtaining external sources then you don't need to manually get the source
128 above via subversion. **
129
Christian Heimese8954f82007-11-22 11:21:16 +0000130_ssl
131 Python wrapper for the secure sockets library.
132
133 Get the source code through
134
Zachary Ware7876f722014-10-25 23:04:33 -0500135 svn export http://svn.python.org/projects/external/openssl-1.0.1j
Christian Heimese8954f82007-11-22 11:21:16 +0000136
Trent Nelsondbc114a2008-04-02 15:01:00 +0000137 ** NOTE: if you use the Tools\buildbot\external(-amd64).bat approach for
138 obtaining external sources then you don't need to manually get the source
139 above via subversion. **
140
Zachary Ware4f3395f2015-01-15 11:16:51 -0600141 The NASM assembler is required to build OpenSSL. If you use the
Zachary Ware247b6442014-11-01 17:11:08 -0500142 Tools\buildbot\external(-amd64).bat method for getting sources, it also
143 downloads a version of NASM, which the ssl build script will add to PATH.
Zachary Ware4f3395f2015-01-15 11:16:51 -0600144 Otherwise, you can download the NASM installer from
145 http://www.nasm.us/
146 and add NASM to your PATH.
Christian Heimes3971f6b2007-11-30 19:18:08 +0000147
148 You can also install ActivePerl from
Hirokazu Yamamoto59734be2010-12-09 08:01:18 +0000149 http://www.activestate.com/activeperl/
Zachary Waree0afd8e2013-11-03 21:43:33 -0600150 if you like to use the official sources instead of the files from
Christian Heimes8b011402007-11-27 21:28:40 +0000151 python's subversion repository. The svn version contains pre-build
152 makefiles and assembly files.
Christian Heimese8954f82007-11-22 11:21:16 +0000153
Christian Heimes8b011402007-11-27 21:28:40 +0000154 The build process makes sure that no patented algorithms are included.
Zachary Waree0afd8e2013-11-03 21:43:33 -0600155 For now RC5, MDC2 and IDEA are excluded from the build. You may have
Christian Heimes8b011402007-11-27 21:28:40 +0000156 to manually remove $(OBJ_D)\i_*.obj from ms\nt.mak if the build process
157 complains about missing files or forbidden IDEA. Again the files provided
158 in the subversion repository are already fixed.
Christian Heimese8954f82007-11-22 11:21:16 +0000159
160 The MSVC project simply invokes PCBuild/build_ssl.py to perform
161 the build. This Python script locates and builds your OpenSSL
162 installation, then invokes a simple makefile to build the final .pyd.
163
164 build_ssl.py attempts to catch the most common errors (such as not
165 being able to find OpenSSL sources, or not being able to find a Perl
166 that works with OpenSSL) and give a reasonable error message.
167 If you have a problem that doesn't seem to be handled correctly
168 (eg, you know you have ActivePerl but we can't find it), please take
169 a peek at build_ssl.py and suggest patches. Note that build_ssl.py
170 should be able to be run directly from the command-line.
171
172 build_ssl.py/MSVC isn't clever enough to clean OpenSSL - you must do
173 this by hand.
174
Trent Nelsondbc114a2008-04-02 15:01:00 +0000175The subprojects above wrap external projects Python doesn't control, and as
Zachary Waree0afd8e2013-11-03 21:43:33 -0600176such, a little more work is required in order to download the relevant source
Trent Nelsondbc114a2008-04-02 15:01:00 +0000177files for each project before they can be built. The buildbots do this each
Zachary Waree0afd8e2013-11-03 21:43:33 -0600178time they're built, so the easiest approach is to run either external.bat or
Trent Nelsondbc114a2008-04-02 15:01:00 +0000179external-amd64.bat in the ..\Tools\buildbot directory from ..\, i.e.:
180
181 C:\..\svn.python.org\projects\python\trunk\PCbuild>cd ..
182 C:\..\svn.python.org\projects\python\trunk>Tools\buildbot\external.bat
183
184This extracts all the external subprojects from http://svn.python.org/external
Zachary Waree0afd8e2013-11-03 21:43:33 -0600185via Subversion (so you'll need an svn.exe on your PATH) and places them in
Zachary Ware21a23502014-11-01 22:34:09 -0500186..\externals (relative to this directory). The external(-amd64).bat scripts
187will also build a debug build of Tcl/Tk; there aren't any equivalent batch files
Trent Nelsondbc114a2008-04-02 15:01:00 +0000188for building release versions of Tcl/Tk lying around in the Tools\buildbot
189directory. If you need to build a release version of Tcl/Tk it isn't hard
190though, take a look at the relevant external(-amd64).bat file and find the
191two nmake lines, then call each one without the 'DEBUG=1' parameter, i.e.:
192
193The external-amd64.bat file contains this for tcl:
194 nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
195
196So for a release build, you'd call it as:
197 nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
198
199 XXX Should we compile with OPTS=threads?
200 XXX Our installer copies a lot of stuff out of the Tcl/Tk install
201 XXX directory. Is all of that really needed for Python use of Tcl/Tk?
202
203This will be cleaned up in the future; ideally Tcl/Tk will be brought into our
204pcbuild.sln as custom .vcproj files, just as we've recently done with the
Georg Brandle4c1f112008-09-21 07:24:11 +0000205_bsddb.vcproj and sqlite3.vcproj files, which will remove the need for
Trent Nelsondbc114a2008-04-02 15:01:00 +0000206Tcl/Tk to be built separately via a batch file.
207
Christian Heimese8954f82007-11-22 11:21:16 +0000208Building for Itanium
209--------------------
210
Christian Heimes8b011402007-11-27 21:28:40 +0000211Official support for Itanium builds have been dropped from the build. Please
Christian Heimes95d64472008-02-09 19:55:22 +0000212contact us and provide patches if you are interested in Itanium builds.
Christian Heimes8b011402007-11-27 21:28:40 +0000213
Christian Heimese8954f82007-11-22 11:21:16 +0000214Building for AMD64
215------------------
216
Christian Heimes8b011402007-11-27 21:28:40 +0000217The build process for AMD64 / x64 is very similar to standard builds. You just
Martin v. Löwis9e051352008-02-29 18:54:45 +0000218have to set x64 as platform. In addition, the HOST_PYTHON environment variable
219must point to a Python interpreter (at least 2.4), to support cross-compilation.
Christian Heimese8954f82007-11-22 11:21:16 +0000220
221Building Python Using the free MS Toolkit Compiler
222--------------------------------------------------
223
Christian Heimes3971f6b2007-11-30 19:18:08 +0000224Microsoft has withdrawn the free MS Toolkit Compiler, so this can no longer
225be considered a supported option. Instead you can use the free VS C++ Express
226Edition.
Christian Heimese8954f82007-11-22 11:21:16 +0000227
Christian Heimes8b011402007-11-27 21:28:40 +0000228Profile Guided Optimization
229---------------------------
Christian Heimese8954f82007-11-22 11:21:16 +0000230
Thomas Heller44c38c12008-01-10 18:45:40 +0000231The solution has two configurations for PGO. The PGInstrument
232configuration must be build first. The PGInstrument binaries are
Zachary Waree0afd8e2013-11-03 21:43:33 -0600233linked against a profiling library and contain extra debug
Thomas Heller44c38c12008-01-10 18:45:40 +0000234information. The PGUpdate configuration takes the profiling data and
235generates optimized binaries.
Christian Heimes3d2f5642007-12-06 21:13:06 +0000236
237The build_pgo.bat script automates the creation of optimized binaries. It
238creates the PGI files, runs the unit test suite or PyBench with the PGI
239python and finally creates the optimized files.
240
Zachary Waree0afd8e2013-11-03 21:43:33 -0600241http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.90).aspx
Christian Heimese8954f82007-11-22 11:21:16 +0000242
Christian Heimes3971f6b2007-11-30 19:18:08 +0000243Static library
244--------------
245
246The solution has no configuration for static libraries. However it is easy
Zachary Waree0afd8e2013-11-03 21:43:33 -0600247it build a static library instead of a DLL. You simply have to set the
Christian Heimes3971f6b2007-11-30 19:18:08 +0000248"Configuration Type" to "Static Library (.lib)" and alter the preprocessor
249macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may also have to
Zachary Waree0afd8e2013-11-03 21:43:33 -0600250change the "Runtime Library" from "Multi-threaded DLL (/MD)" to
Christian Heimes3971f6b2007-11-30 19:18:08 +0000251"Multi-threaded (/MT)".
252
Christian Heimes18679942007-12-05 21:57:25 +0000253Visual Studio properties
254------------------------
255
Zachary Waree0afd8e2013-11-03 21:43:33 -0600256The PCbuild solution makes heavy use of Visual Studio property files
Christian Heimes18679942007-12-05 21:57:25 +0000257(*.vsprops). The properties can be viewed and altered in the Property
258Manager (View -> Other Windows -> Property Manager).
259
Christian Heimes3d2f5642007-12-06 21:13:06 +0000260 * debug (debug macro: _DEBUG)
Christian Heimes18679942007-12-05 21:57:25 +0000261 * pginstrument (PGO)
262 * pgupdate (PGO)
263 +-- pginstrument
264 * pyd (python extension, release build)
265 +-- release
266 +-- pyproject
267 * pyd_d (python extension, debug build)
268 +-- debug
269 +-- pyproject
Christian Heimes3d2f5642007-12-06 21:13:06 +0000270 * pyproject (base settings for all projects, user macros like PyDllName)
271 * release (release macro: NDEBUG)
Christian Heimes18679942007-12-05 21:57:25 +0000272 * x64 (AMD64 / x64 platform specific settings)
273
274The pyproject propertyfile defines _WIN32 and x64 defines _WIN64 and _M_X64
275although the macros are set by the compiler, too. The GUI doesn't always know
276about the macros and confuse the user with false information.
277
Christian Heimese8954f82007-11-22 11:21:16 +0000278YOUR OWN EXTENSION DLLs
279-----------------------
Christian Heimes3d2f5642007-12-06 21:13:06 +0000280
Christian Heimese8954f82007-11-22 11:21:16 +0000281If you want to create your own extension module DLL, there's an example
282with easy-to-follow instructions in ../PC/example/; read the file
283readme.txt there first.