blob: 6f07689ce5cc59f85a949b913652e59d941019af [file] [log] [blame]
Kristján Valur Jónssonc45ea9e2012-05-19 21:10:14 +00001Building Python using VC++ 10.0
Christian Heimes9c99cc02013-09-29 19:02:35 +02002-------------------------------
Christian Heimes57dddfb2008-01-02 18:30:52 +00003
Zachary Ware200bcbc2013-11-03 21:48:54 -06004This directory is used to build Python for Win32 and x64 platforms, e.g.
5Windows XP, Vista and Windows Server 2008. In order to build 32-bit
Christian Heimes9c99cc02013-09-29 19:02:35 +02006debug and release executables, Microsoft Visual C++ 2010 Express Edition is
Trent Nelson52037272008-04-02 15:06:49 +00007required at the very least. In order to build 64-bit debug and release
Christian Heimes9c99cc02013-09-29 19:02:35 +02008executables, Visual Studio 2010 Standard Edition is required at the very
Trent Nelson52037272008-04-02 15:06:49 +00009least. In order to build all of the above, as well as generate release builds
Christian Heimes9c99cc02013-09-29 19:02:35 +020010that make use of Profile Guided Optimisation (PG0), Visual Studio 2010
Trent Nelson52037272008-04-02 15:06:49 +000011Professional 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.
Guido van Rossum15b239f1998-05-26 14:16:23 +000015
Christian Heimes5b5e81c2007-12-31 16:14:33 +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.
Guido van Rossum15b239f1998-05-26 14:16:23 +000021
Christian Heimes5b5e81c2007-12-31 16:14:33 +000022The PCbuild directory is compatible with all versions of Visual Studio from
23VS C++ Express Edition over the standard edition up to the professional
Benjamin Peterson9bc93512008-09-22 22:10:59 +000024edition. However the express edition does not support features like solution
Christian Heimes5b5e81c2007-12-31 16:14:33 +000025folders or profile guided optimization (PGO). The missing bits and pieces
26won't stop you from building Python.
Guido van Rossum15b239f1998-05-26 14:16:23 +000027
Christian Heimes5b5e81c2007-12-31 16:14:33 +000028The solution is configured to build the projects in the correct order. "Build
Christian Heimesa8223142008-02-09 20:58:00 +000029Solution" or F7 takes care of dependencies except for x64 builds. To make
Zachary Ware200bcbc2013-11-03 21:48:54 -060030cross compiling x64 builds on a 32bit OS possible the x64 builds require a
Christian Heimes5b5e81c2007-12-31 16:14:33 +00003132bit version of Python.
Guido van Rossum15b239f1998-05-26 14:16:23 +000032
Christian Heimes5b5e81c2007-12-31 16:14:33 +000033NOTE:
34 You probably don't want to build most of the other subprojects, unless
35 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)
Guido van Rossum15b239f1998-05-26 14:16:23 +000038
39When using the Debug setting, the output files have a _d added to
Georg Brandlfa2c61a2011-02-20 10:41:31 +000040their name: python33_d.dll, python_d.exe, parser_d.pyd, and so on. Both
Christian Heimesa8223142008-02-09 20:58:00 +000041the build and rt batch files accept a -d option for debug builds.
Guido van Rossume79cf321998-07-07 22:35:03 +000042
Christian Heimes5b5e81c2007-12-31 16:14:33 +000043The 32bit builds end up in the solution folder PCbuild while the x64 builds
44land in the amd64 subfolder. The PGI and PGO builds for profile guided
45optimization end up in their own folders, too.
46
Christian Heimes57dddfb2008-01-02 18:30:52 +000047Legacy support
48--------------
49
Zachary Ware200bcbc2013-11-03 21:48:54 -060050You can find build directories for older versions of Visual Studio and
Christian Heimes57dddfb2008-01-02 18:30:52 +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 Yamamoto0b0ebb42010-10-01 10:40:49 +000058PC/VS8.0/
Christian Heimes57dddfb2008-01-02 18:30:52 +000059 Visual Studio 2005 (8.0)
Christian Heimes51763372013-09-29 19:10:07 +020060PC/VS9.0/
61 Visual Studio 2008 (9.0)
Christian Heimes57dddfb2008-01-02 18:30:52 +000062
63
64C RUNTIME
65---------
66
Zachary Ware200bcbc2013-11-03 21:48:54 -060067Visual Studio 2010 uses version 10 of the C runtime (MSVCRT10). The executables
Kristján Valur Jónssonc45ea9e2012-05-19 21:10:14 +000068no longer use the "Side by Side" assemblies used in previous versions of the
69compiler. This simplifies distribution of applications.
Zachary Ware200bcbc2013-11-03 21:48:54 -060070The run time libraries are available under the VC/Redist folder of your visual studio
Kristján Valur Jónssonc45ea9e2012-05-19 21:10:14 +000071distribution. For more info, see the Readme in the VC/Redist folder.
Christian Heimes57dddfb2008-01-02 18:30:52 +000072
Tim Peters4b5fb072000-07-01 00:03:43 +000073SUBPROJECTS
74-----------
Tim Peters610a8272000-07-01 02:51:23 +000075These subprojects should build out of the box. Subprojects other than the
Tim Petersbefc97c2001-01-18 19:01:39 +000076main ones (pythoncore, python, pythonw) generally build a DLL (renamed to
Tim Peters610a8272000-07-01 02:51:23 +000077.pyd) from a specific module so that users don't have to load the code
Tim Peters4b5fb072000-07-01 00:03:43 +000078supporting that module unless they import the module.
Guido van Rossume79cf321998-07-07 22:35:03 +000079
Tim Peters97c96402001-01-17 23:23:13 +000080pythoncore
Tim Peters4b5fb072000-07-01 00:03:43 +000081 .dll and .lib
82python
83 .exe
84pythonw
85 pythonw.exe, a variant of python.exe that doesn't pop up a DOS box
86_socket
87 socketmodule.c
Tim Petersd66595f2001-02-04 03:09:53 +000088_testcapi
Tim Petersb16c56f2001-02-02 21:24:51 +000089 tests of the Python C API, run via Lib/test/test_capi.py, and
Tim Petersd66595f2001-02-04 03:09:53 +000090 implemented by module Modules/_testcapimodule.c
Stefan Krah9a2d99e2012-02-25 12:24:21 +010091_testbuffer
92 buffer protocol tests, run via Lib/test/test_buffer.py, and
93 implemented by module Modules/_testbuffer.c
Tim Petersb012a152002-02-13 23:56:46 +000094pyexpat
95 Python wrapper for accelerated XML parsing, which incorporates stable
96 code from the Expat project: http://sourceforge.net/projects/expat/
Tim Peters4b5fb072000-07-01 00:03:43 +000097select
98 selectmodule.c
Tim Peters19f52c22001-01-24 10:07:22 +000099unicodedata
Tim Peters4b5fb072000-07-01 00:03:43 +0000100 large tables of Unicode data
Tim Peters4b5fb072000-07-01 00:03:43 +0000101winsound
102 play sounds (typically .wav files) under Windows
103
Trent Nelson52037272008-04-02 15:06:49 +0000104Python-controlled subprojects that wrap external projects:
Trent Nelson52037272008-04-02 15:06:49 +0000105_sqlite3
Zachary Ware200bcbc2013-11-03 21:48:54 -0600106 Wraps SQLite 3.7.12, which is currently built by sqlite3.vcxproj.
Tim Peters4b5fb072000-07-01 00:03:43 +0000107_tkinter
Georg Brandl1158a332009-06-04 09:30:30 +0000108 Wraps the Tk windowing system. Unlike _sqlite3, there's no
Zachary Ware200bcbc2013-11-03 21:48:54 -0600109 corresponding tcltk.vcxproj-type project that builds Tcl/Tk from vcxproj's
Trent Nelson52037272008-04-02 15:06:49 +0000110 within our pcbuild.sln, which means this module expects to find a
111 pre-built Tcl/Tk in either ..\..\tcltk for 32-bit or ..\..\tcltk64 for
112 64-bit (relative to this directory). See below for instructions to build
Zachary Ware200bcbc2013-11-03 21:48:54 -0600113 Tcl/Tk.
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200114_bz2
115 Python wrapper for the libbzip2 compression library. Homepage
116 http://www.bzip.org/
Martin v. Löwisf6f79252006-03-13 13:48:05 +0000117 Download the source from the python.org copy into the dist
118 directory:
119
Martin v. Löwisecc58772012-05-14 13:52:03 +0200120 svn export http://svn.python.org/projects/external/bzip2-1.0.6
Tim Peters077736b2002-11-14 23:24:40 +0000121
Trent Nelson52037272008-04-02 15:06:49 +0000122 ** NOTE: if you use the Tools\buildbot\external(-amd64).bat approach for
123 obtaining external sources then you don't need to manually get the source
124 above via subversion. **
Nadeem Vawda3ff069e2011-11-30 00:25:06 +0200125_lzma
126 Python wrapper for the liblzma compression library.
127
128 Download the pre-built Windows binaries from http://tukaani.org/xz/, and
129 extract to ..\xz-5.0.3. If you are using a more recent version of liblzma,
130 it will be necessary to rename the directory from xz-<VERSION> to xz-5.0.3.
Tim Petersb0ead4e2002-11-09 04:48:58 +0000131
Mark Hammondf229f9f2002-12-03 05:47:26 +0000132_ssl
Tim Peterse8bcb252002-12-04 02:39:52 +0000133 Python wrapper for the secure sockets library.
Tim Peters4b5fb072000-07-01 00:03:43 +0000134
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000135 Get the source code through
Mark Hammondf229f9f2002-12-03 05:47:26 +0000136
Georg Brandl84fc4ba2013-05-12 19:50:34 +0200137 svn export http://svn.python.org/projects/external/openssl-1.0.1e
Tim Peterse8bcb252002-12-04 02:39:52 +0000138
Trent Nelson52037272008-04-02 15:06:49 +0000139 ** NOTE: if you use the Tools\buildbot\external(-amd64).bat approach for
140 obtaining external sources then you don't need to manually get the source
141 above via subversion. **
142
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000143 Alternatively, get the latest version from http://www.openssl.org.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000144 You can (theoretically) use any version of OpenSSL you like - the
145 build process will automatically select the latest version.
146
Christian Heimesc81549f2013-06-14 15:40:28 +0200147 You must install the NASM assembler 2.10 or newer from
Benjamin Petersone5384b02008-10-04 22:00:42 +0000148 http://nasm.sf.net
Zachary Ware200bcbc2013-11-03 21:48:54 -0600149 for x86 builds. Put nasm.exe anywhere in your PATH. More recent
Christian Heimesc81549f2013-06-14 15:40:28 +0200150 versions of OpenSSL may need a later version of NASM. If OpenSSL's self
151 tests don't pass, you should first try to update NASM and do a full
152 rebuild of OpenSSL.
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000153
154 You can also install ActivePerl from
Hirokazu Yamamoto7c3d7092010-10-28 17:57:25 +0000155 http://www.activestate.com/activeperl/
Zachary Ware200bcbc2013-11-03 21:48:54 -0600156 if you like to use the official sources instead of the files from
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000157 python's subversion repository. The svn version contains pre-build
158 makefiles and assembly files.
159
160 The build process makes sure that no patented algorithms are included.
Zachary Ware200bcbc2013-11-03 21:48:54 -0600161 For now RC5, MDC2 and IDEA are excluded from the build. You may have
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000162 to manually remove $(OBJ_D)\i_*.obj from ms\nt.mak if the build process
163 complains about missing files or forbidden IDEA. Again the files provided
164 in the subversion repository are already fixed.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000165
166 The MSVC project simply invokes PCBuild/build_ssl.py to perform
Tim Peterse8bcb252002-12-04 02:39:52 +0000167 the build. This Python script locates and builds your OpenSSL
Mark Hammondf229f9f2002-12-03 05:47:26 +0000168 installation, then invokes a simple makefile to build the final .pyd.
169
170 build_ssl.py attempts to catch the most common errors (such as not
171 being able to find OpenSSL sources, or not being able to find a Perl
172 that works with OpenSSL) and give a reasonable error message.
173 If you have a problem that doesn't seem to be handled correctly
174 (eg, you know you have ActivePerl but we can't find it), please take
175 a peek at build_ssl.py and suggest patches. Note that build_ssl.py
176 should be able to be run directly from the command-line.
177
Tim Peterse8bcb252002-12-04 02:39:52 +0000178 build_ssl.py/MSVC isn't clever enough to clean OpenSSL - you must do
179 this by hand.
Tim Peters4b5fb072000-07-01 00:03:43 +0000180
Trent Nelson52037272008-04-02 15:06:49 +0000181The subprojects above wrap external projects Python doesn't control, and as
Zachary Ware200bcbc2013-11-03 21:48:54 -0600182such, a little more work is required in order to download the relevant source
Trent Nelson52037272008-04-02 15:06:49 +0000183files for each project before they can be built. The buildbots do this each
Zachary Ware200bcbc2013-11-03 21:48:54 -0600184time they're built, so the easiest approach is to run either external.bat or
Trent Nelson52037272008-04-02 15:06:49 +0000185external-amd64.bat in the ..\Tools\buildbot directory from ..\, i.e.:
186
187 C:\..\svn.python.org\projects\python\trunk\PCbuild>cd ..
188 C:\..\svn.python.org\projects\python\trunk>Tools\buildbot\external.bat
189
190This extracts all the external subprojects from http://svn.python.org/external
Zachary Ware200bcbc2013-11-03 21:48:54 -0600191via Subversion (so you'll need an svn.exe on your PATH) and places them in
Trent Nelson52037272008-04-02 15:06:49 +0000192..\.. (relative to this directory). The external(-amd64).bat scripts will
193also build a debug build of Tcl/Tk; there aren't any equivalent batch files
194for building release versions of Tcl/Tk lying around in the Tools\buildbot
195directory. If you need to build a release version of Tcl/Tk it isn't hard
196though, take a look at the relevant external(-amd64).bat file and find the
197two nmake lines, then call each one without the 'DEBUG=1' parameter, i.e.:
198
199The external-amd64.bat file contains this for tcl:
Zachary Ware200bcbc2013-11-03 21:48:54 -0600200 nmake -f makefile.vc DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
Trent Nelson52037272008-04-02 15:06:49 +0000201
202So for a release build, you'd call it as:
Zachary Ware200bcbc2013-11-03 21:48:54 -0600203 nmake -f makefile.vc MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
Trent Nelson52037272008-04-02 15:06:49 +0000204
205 XXX Should we compile with OPTS=threads?
206 XXX Our installer copies a lot of stuff out of the Tcl/Tk install
207 XXX directory. Is all of that really needed for Python use of Tcl/Tk?
208
209This will be cleaned up in the future; ideally Tcl/Tk will be brought into our
Zachary Ware200bcbc2013-11-03 21:48:54 -0600210pcbuild.sln as custom .vcxproj files, just as we've recently done with the
211sqlite3.vcxproj file, which will remove the need for Tcl/Tk to be built
Georg Brandl1158a332009-06-04 09:30:30 +0000212separately via a batch file.
Trent Nelson52037272008-04-02 15:06:49 +0000213
214XXX trent.nelson 02-Apr-08:
215 Having the external subprojects in ..\.. relative to this directory is a
216 bit of a nuisance when you're working on py3k and trunk in parallel and
217 your directory layout mimics that of Python's subversion layout, e.g.:
218
219 C:\..\svn.python.org\projects\python\trunk
220 C:\..\svn.python.org\projects\python\branches\py3k
221 C:\..\svn.python.org\projects\python\branches\release25-maint
222
223 I'd like to change things so that external subprojects are fetched from
224 ..\external instead of ..\.., then provide some helper scripts or batch
225 files that would set up a new ..\external directory with svn checkouts of
226 the relevant branches in http://svn.python.org/projects/external/, or
227 alternatively, use junctions to link ..\external with a pre-existing
228 externals directory being used by another branch. i.e. if I'm usually
229 working on trunk (and have previously created trunk\external via the
230 provided batch file), and want to do some work on py3k, I'd set up a
231 junction as follows (using the directory structure above as an example):
232
233 C:\..\python\trunk\external <- already exists and has built versions
Zachary Ware200bcbc2013-11-03 21:48:54 -0600234 of the external subprojects
Trent Nelson52037272008-04-02 15:06:49 +0000235
236 C:\..\python\branches\py3k>linkd.exe external ..\..\trunk\external
237 Link created at: external
238
239 Only a slight tweak would be needed to the buildbots such that bots
240 building trunk and py3k could make use of the same facility. (2.5.x
241 builds need to be kept separate as they're using Visual Studio 7.1.)
242/XXX trent.nelson 02-Apr-08
243
Martin v. Löwis13e50fe2004-07-20 14:37:48 +0000244Building for Itanium
245--------------------
246
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000247Official support for Itanium builds have been dropped from the build. Please
Christian Heimesa8223142008-02-09 20:58:00 +0000248contact us and provide patches if you are interested in Itanium builds.
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000249
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000250Building for AMD64
251------------------
252
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000253The build process for AMD64 / x64 is very similar to standard builds. You just
Martin v. Löwis1561bab2008-02-29 19:39:25 +0000254have to set x64 as platform. In addition, the HOST_PYTHON environment variable
255must point to a Python interpreter (at least 2.4), to support cross-compilation.
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000256
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000257Building Python Using the free MS Toolkit Compiler
258--------------------------------------------------
259
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000260Microsoft has withdrawn the free MS Toolkit Compiler, so this can no longer
261be considered a supported option. Instead you can use the free VS C++ Express
262Edition.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000263
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000264Profile Guided Optimization
265---------------------------
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000266
Christian Heimes25bb7832008-01-11 16:17:00 +0000267The solution has two configurations for PGO. The PGInstrument
268configuration must be build first. The PGInstrument binaries are
Zachary Ware200bcbc2013-11-03 21:48:54 -0600269linked against a profiling library and contain extra debug
Christian Heimes25bb7832008-01-11 16:17:00 +0000270information. The PGUpdate configuration takes the profiling data and
271generates optimized binaries.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000272
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000273The build_pgo.bat script automates the creation of optimized binaries. It
274creates the PGI files, runs the unit test suite or PyBench with the PGI
275python and finally creates the optimized files.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000276
Zachary Ware200bcbc2013-11-03 21:48:54 -0600277http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.100).aspx
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000278
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000279Static library
280--------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000281
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000282The solution has no configuration for static libraries. However it is easy
Zachary Ware200bcbc2013-11-03 21:48:54 -0600283it build a static library instead of a DLL. You simply have to set the
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000284"Configuration Type" to "Static Library (.lib)" and alter the preprocessor
285macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may also have to
Zachary Ware200bcbc2013-11-03 21:48:54 -0600286change the "Runtime Library" from "Multi-threaded DLL (/MD)" to
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000287"Multi-threaded (/MT)".
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000288
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000289Visual Studio properties
290------------------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000291
Zachary Ware200bcbc2013-11-03 21:48:54 -0600292The PCbuild solution makes heavy use of Visual Studio property files
293(*.props). The properties can be viewed and altered in the Property
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000294Manager (View -> Other Windows -> Property Manager).
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000295
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000296 * debug (debug macro: _DEBUG)
297 * pginstrument (PGO)
298 * pgupdate (PGO)
299 +-- pginstrument
300 * pyd (python extension, release build)
301 +-- release
302 +-- pyproject
303 * pyd_d (python extension, debug build)
304 +-- debug
305 +-- pyproject
306 * pyproject (base settings for all projects, user macros like PyDllName)
307 * release (release macro: NDEBUG)
308 * x64 (AMD64 / x64 platform specific settings)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000309
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000310The pyproject propertyfile defines _WIN32 and x64 defines _WIN64 and _M_X64
311although the macros are set by the compiler, too. The GUI doesn't always know
312about the macros and confuse the user with false information.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000313
Tim Petersf9a4a6e2000-07-01 20:38:27 +0000314YOUR OWN EXTENSION DLLs
Tim Peters4b5fb072000-07-01 00:03:43 +0000315-----------------------
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000316
Tim Peters4b5fb072000-07-01 00:03:43 +0000317If you want to create your own extension module DLL, there's an example
318with easy-to-follow instructions in ../PC/example/; read the file
319readme.txt there first.