blob: 7d57726612bdce71f620dc148e95432bad47bbca [file] [log] [blame]
Tim Golden7d052362013-10-25 08:58:16 +01001Building Python using Microsoft Visual C++
2------------------------------------------
Christian Heimes57dddfb2008-01-02 18:30:52 +00003
Tim Golden7d052362013-10-25 08:58:16 +01004This directory is used to build CPython for Microsoft Windows NT version
55.1 or higher (Windows XP, Windows Server 2003, or later) on 32 and 64
6bit platforms. Using this directory requires an installation of
7Microsoft Visual C++ 2010 (MSVC 10.0) of any edition. The specific
8requirements are as follows:
Zachary Ware5f3e3c32014-03-19 14:46:25 -05009
Tim Golden7d052362013-10-25 08:58:16 +010010Visual C++ 2010 Express Edition
11 Required for building 32-bit Debug and Release configuration builds.
Zachary Wareef035652014-07-07 14:33:24 -050012 The Python build solution pcbuild.sln makes use of Solution Folders,
13 which this edition does not support. Any time pcbuild.sln is opened
14 or reloaded by Visual C++, a warning about Solution Folders will be
15 displayed which can be safely dismissed with no impact on your
16 ability to build Python.
Tim Golden7d052362013-10-25 08:58:16 +010017Visual Studio 2010 Professional Edition
Zachary Ware5f3e3c32014-03-19 14:46:25 -050018 Required for building 64-bit Debug and Release configuration builds
19Visual Studio 2010 Premium Edition
Tim Golden7d052362013-10-25 08:58:16 +010020 Required for building Release configuration builds that make use of
Zachary Ware5f3e3c32014-03-19 14:46:25 -050021 Profile Guided Optimization (PGO), on either platform.
22
Zachary Ware4856a6a2014-06-13 09:38:50 -050023Installing Service Pack 1 for Visual Studio 2010 is highly recommended
24to avoid LNK1123 errors.
25
Tim Golden7d052362013-10-25 08:58:16 +010026All you need to do to build is open the solution "pcbuild.sln" in Visual
27Studio, select the desired combination of configuration and platform,
28then build with "Build Solution" or the F7 keyboard shortcut. You can
29also build from the command line using the "build.bat" script in this
30directory. The solution is configured to build the projects in the
31correct order.
Guido van Rossum15b239f1998-05-26 14:16:23 +000032
Tim Golden7d052362013-10-25 08:58:16 +010033The solution currently supports two platforms. The Win32 platform is
34used to build standard x86-compatible 32-bit binaries, output into this
35directory. The x64 platform is used for building 64-bit AMD64 (aka
36x86_64 or EM64T) binaries, output into the amd64 sub-directory which
37will be created if it doesn't already exist. The Itanium (IA-64)
38platform is no longer supported. See the "Building for AMD64" section
39below for more information about 64-bit builds.
Guido van Rossum15b239f1998-05-26 14:16:23 +000040
Tim Golden7d052362013-10-25 08:58:16 +010041Four configuration options are supported by the solution:
42Debug
43 Used to build Python with extra debugging capabilities, equivalent
44 to using ./configure --with-pydebug on UNIX. All binaries built
45 using this configuration have "_d" added to their name:
46 python34_d.dll, python_d.exe, parser_d.pyd, and so on. Both the
47 build and rt (run test) batch files in this directory accept a -d
48 option for debug builds. If you are building Python to help with
49 development of CPython, you will most likely use this configuration.
50PGInstrument, PGUpdate
51 Used to build Python in Release configuration using PGO, which
Zachary Ware2170b142014-07-07 14:31:34 -050052 requires Premium Edition of Visual Studio. See the "Profile
Tim Golden7d052362013-10-25 08:58:16 +010053 Guided Optimization" section below for more information. Build
54 output from each of these configurations lands in its own
55 sub-directory of this directory. The official Python releases are
56 built using these configurations.
57Release
58 Used to build Python as it is meant to be used in production
59 settings, though without PGO.
Guido van Rossum15b239f1998-05-26 14:16:23 +000060
Christian Heimes5b5e81c2007-12-31 16:14:33 +000061
Christian Heimes57dddfb2008-01-02 18:30:52 +000062Legacy support
63--------------
64
Tim Golden7d052362013-10-25 08:58:16 +010065You can find build directories for older versions of Visual Studio and
66Visual C++ in the PC directory. The legacy build directories are no
67longer actively maintained and may not work out of the box.
Christian Heimes57dddfb2008-01-02 18:30:52 +000068
Tim Golden7d052362013-10-25 08:58:16 +010069Currently, the only legacy build directory is PC\VS9.0, for Visual
70Studio 2008 (9.0).
Christian Heimes57dddfb2008-01-02 18:30:52 +000071
72
Tim Golden7d052362013-10-25 08:58:16 +010073C Runtime
Christian Heimes57dddfb2008-01-02 18:30:52 +000074---------
75
Tim Golden7d052362013-10-25 08:58:16 +010076Visual Studio 2010 uses version 10 of the C runtime (MSVCRT10). The
77executables no longer use the "Side by Side" assemblies used in previous
78versions of the compiler. This simplifies distribution of applications.
Christian Heimes57dddfb2008-01-02 18:30:52 +000079
Tim Golden7d052362013-10-25 08:58:16 +010080The run time libraries are available under the VC/Redist folder of your
81Visual Studio distribution. For more info, see the Readme in the
82VC/Redist folder.
Guido van Rossume79cf321998-07-07 22:35:03 +000083
Tim Golden7d052362013-10-25 08:58:16 +010084
85Sub-Projects
86------------
87
88The CPython project is split up into several smaller sub-projects which
89are managed by the pcbuild.sln solution file. Each sub-project is
90represented by a .vcxproj and a .vcxproj.filters file starting with the
91name of the sub-project. These sub-projects fall into a few general
92categories:
93
94The following sub-projects represent the bare minimum required to build
95a functioning CPython interpreter. If nothing else builds but these,
96you'll have a very limited but usable python.exe:
Tim Peters97c96402001-01-17 23:23:13 +000097pythoncore
Tim Peters4b5fb072000-07-01 00:03:43 +000098 .dll and .lib
99python
100 .exe
Tim Golden7d052362013-10-25 08:58:16 +0100101kill_python
102 kill_python.exe, a small program designed to kill any instances of
103 python(_d).exe that are running and live in the build output
104 directory; this is meant to avoid build issues due to locked files
105make_buildinfo, make_versioninfo
106 helpers to provide necessary information to the build process
107
108These sub-projects provide extra executables that are useful for running
109CPython in different ways:
Tim Peters4b5fb072000-07-01 00:03:43 +0000110pythonw
Tim Golden7d052362013-10-25 08:58:16 +0100111 pythonw.exe, a variant of python.exe that doesn't open a Command
112 Prompt window
113pylauncher
114 py.exe, the Python Launcher for Windows, see
115 http://docs.python.org/3/using/windows.html#launcher
116pywlauncher
117 pyw.exe, a variant of py.exe that doesn't open a Command Prompt
118 window
Zachary Waree0881f42013-11-05 21:55:46 -0600119_testembed
120 _testembed.exe, a small program that embeds Python for testing
121 purposes, used by test_capi.py
Tim Golden7d052362013-10-25 08:58:16 +0100122
123These are miscellaneous sub-projects that don't really fit the other
124categories. By default, these projects do not build in Debug
125configuration:
126_freeze_importlib
127 _freeze_importlib.exe, used to regenerate Python\importlib.h after
128 changes have been made to Lib\importlib\_bootstrap.py
129bdist_wininst
130 ..\Lib\distutils\command\wininst-10.0[-amd64].exe, the base
131 executable used by the distutils bdist_wininst command
132python3dll
133 python3.dll, the PEP 384 Stable ABI dll
134xxlimited
135 builds an example module that makes use of the PEP 384 Stable ABI,
136 see Modules\xxlimited.c
137
138The following sub-projects are for individual modules of the standard
139library which are implemented in C; each one builds a DLL (renamed to
140.pyd) of the same name as the project:
141_ctypes
142_ctypes_test
143_decimal
144_elementtree
145_hashlib
146_msi
147_multiprocessing
148_overlapped
Tim Peters4b5fb072000-07-01 00:03:43 +0000149_socket
Tim Petersd66595f2001-02-04 03:09:53 +0000150_testcapi
Stefan Krah9a2d99e2012-02-25 12:24:21 +0100151_testbuffer
Tim Golden7d052362013-10-25 08:58:16 +0100152_testimportmultiple
Tim Petersb012a152002-02-13 23:56:46 +0000153pyexpat
Tim Peters4b5fb072000-07-01 00:03:43 +0000154select
Tim Peters19f52c22001-01-24 10:07:22 +0000155unicodedata
Tim Peters4b5fb072000-07-01 00:03:43 +0000156winsound
Tim Peters4b5fb072000-07-01 00:03:43 +0000157
Tim Golden7d052362013-10-25 08:58:16 +0100158The following Python-controlled sub-projects wrap external projects.
159Note that these external libraries are not necessary for a working
160interpreter, but they do implement several major features. See the
161"Getting External Sources" section below for additional information
162about getting the source for building these libraries. The sub-projects
163are:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200164_bz2
Tim Golden7d052362013-10-25 08:58:16 +0100165 Python wrapper for version 1.0.6 of the libbzip2 compression library
166 Homepage:
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200167 http://www.bzip.org/
Nadeem Vawda3ff069e2011-11-30 00:25:06 +0200168_lzma
Tim Golden7d052362013-10-25 08:58:16 +0100169 Python wrapper for the liblzma compression library, using pre-built
Martin v. Löwisbaacf4d2013-11-22 19:13:51 +0100170 binaries of XZ Utils version 5.0.5
Tim Golden7d052362013-10-25 08:58:16 +0100171 Homepage:
172 http://tukaani.org/xz/
Mark Hammondf229f9f2002-12-03 05:47:26 +0000173_ssl
Zachary Ware7d55da42014-06-06 01:23:53 -0500174 Python wrapper for version 1.0.1h of the OpenSSL secure sockets
Tim Golden7d052362013-10-25 08:58:16 +0100175 library, which is built by ssl.vcxproj
176 Homepage:
177 http://www.openssl.org/
Tim Peters4b5fb072000-07-01 00:03:43 +0000178
Tim Golden7d052362013-10-25 08:58:16 +0100179 Building OpenSSL requires nasm.exe (the Netwide Assembler), version
180 2.10 or newer from
181 http://www.nasm.us/
182 to be somewhere on your PATH. More recent versions of OpenSSL may
183 need a later version of NASM. If OpenSSL's self tests don't pass,
184 you should first try to update NASM and do a full rebuild of
185 OpenSSL.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000186
Tim Golden7d052362013-10-25 08:58:16 +0100187 If you like to use the official sources instead of the files from
188 python.org's subversion repository, Perl is required to build the
189 necessary makefiles and assembly files. ActivePerl is available
190 from
Hirokazu Yamamoto7c3d7092010-10-28 17:57:25 +0000191 http://www.activestate.com/activeperl/
Tim Golden7d052362013-10-25 08:58:16 +0100192 The svn.python.org version contains pre-built makefiles and assembly
193 files.
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000194
Tim Golden7d052362013-10-25 08:58:16 +0100195 The build process makes sure that no patented algorithms are
196 included. For now RC5, MDC2 and IDEA are excluded from the build.
197 You may have to manually remove $(OBJ_D)\i_*.obj from ms\nt.mak if
198 using official sources; the svn.python.org-hosted version is already
199 fixed.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000200
Tim Golden7d052362013-10-25 08:58:16 +0100201 The ssl.vcxproj sub-project simply invokes PCbuild/build_ssl.py,
202 which locates and builds OpenSSL.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000203
204 build_ssl.py attempts to catch the most common errors (such as not
205 being able to find OpenSSL sources, or not being able to find a Perl
Tim Golden7d052362013-10-25 08:58:16 +0100206 that works with OpenSSL) and give a reasonable error message. If
207 you have a problem that doesn't seem to be handled correctly (e.g.,
208 you know you have ActivePerl but we can't find it), please take a
209 peek at build_ssl.py and suggest patches. Note that build_ssl.py
Mark Hammondf229f9f2002-12-03 05:47:26 +0000210 should be able to be run directly from the command-line.
211
Tim Golden7d052362013-10-25 08:58:16 +0100212 The ssl sub-project does not have the ability to clean the OpenSSL
213 build; if you need to rebuild, you'll have to clean it by hand.
214_sqlite3
Martin v. Löwisa6630692014-03-02 19:42:50 +0100215 Wraps SQLite 3.8.3.1, which is itself built by sqlite3.vcxproj
Tim Golden7d052362013-10-25 08:58:16 +0100216 Homepage:
217 http://www.sqlite.org/
218_tkinter
Martin v. Löwis8d0d3692013-11-23 23:05:27 +0100219 Wraps version 8.6.1 of the Tk windowing system.
Tim Golden7d052362013-10-25 08:58:16 +0100220 Homepage:
221 http://www.tcl.tk/
Tim Peters4b5fb072000-07-01 00:03:43 +0000222
Tim Golden7d052362013-10-25 08:58:16 +0100223 Unlike the other external libraries listed above, Tk must be built
224 separately before the _tkinter module can be built. This means that
225 a pre-built Tcl/Tk installation is expected in ..\..\tcltk (tcltk64
226 for 64-bit) relative to this directory. See "Getting External
227 Sources" below for the easiest method to ensure Tcl/Tk is built.
Trent Nelson52037272008-04-02 15:06:49 +0000228
Trent Nelson52037272008-04-02 15:06:49 +0000229
Tim Golden7d052362013-10-25 08:58:16 +0100230Getting External Sources
231------------------------
232
233The last category of sub-projects listed above wrap external projects
234Python doesn't control, and as such a little more work is required in
235order to download the relevant source files for each project before they
236can be built. The buildbots must ensure that all libraries are present
237before building, so the easiest approach is to run either external.bat
238or external-amd64.bat (depending on platform) in the ..\Tools\buildbot
239directory from ..\, i.e.:
240
241 C:\python\cpython\PCbuild>cd ..
242 C:\python\cpython>Tools\buildbot\external.bat
243
244This extracts all the external sub-projects from
245 http://svn.python.org/projects/external
246via Subversion (so you'll need an svn.exe on your PATH) and places them
247in ..\.. (relative to this directory).
248
249It is also possible to download sources from each project's homepage,
250though you may have to change the names of some folders in order to make
Martin v. Löwisbaacf4d2013-11-22 19:13:51 +0100251things work. For instance, if you were to download a version 5.0.7 of
252XZ Utils, you would need to extract the archive into ..\..\xz-5.0.5
Tim Golden7d052362013-10-25 08:58:16 +0100253anyway, since that is where the solution is set to look for xz. The
254same is true for all other external projects.
255
256The external(-amd64).bat scripts will also build a debug build of
257Tcl/Tk, but there aren't any equivalent batch files for building release
258versions of Tcl/Tk currently available. If you need to build a release
259version of Tcl/Tk, just take a look at the relevant external(-amd64).bat
260file and find the two nmake lines, then call each one without the
261'DEBUG=1' parameter, i.e.:
Trent Nelson52037272008-04-02 15:06:49 +0000262
263The external-amd64.bat file contains this for tcl:
Tim Golden7d052362013-10-25 08:58:16 +0100264 nmake -f makefile.vc DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
Trent Nelson52037272008-04-02 15:06:49 +0000265
266So for a release build, you'd call it as:
Tim Golden7d052362013-10-25 08:58:16 +0100267 nmake -f makefile.vc MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
Trent Nelson52037272008-04-02 15:06:49 +0000268
Martin v. Löwis8d0d3692013-11-23 23:05:27 +0100269Note that the above command is called from within ..\..\tcl-8.6.1.0\win
Tim Golden7d052362013-10-25 08:58:16 +0100270(relative to this directory); don't forget to build Tk as well as Tcl!
Trent Nelson52037272008-04-02 15:06:49 +0000271
Tim Golden7d052362013-10-25 08:58:16 +0100272This will be cleaned up in the future; http://bugs.python.org/issue15968
273tracks adding a new tcltk.vcxproj file that will build Tcl/Tk and Tix
274the same way the other external projects listed above are built.
Trent Nelson52037272008-04-02 15:06:49 +0000275
Martin v. Löwis13e50fe2004-07-20 14:37:48 +0000276
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000277Building for AMD64
278------------------
279
Tim Golden7d052362013-10-25 08:58:16 +0100280The build process for AMD64 / x64 is very similar to standard builds,
281you just have to set x64 as platform. In addition, the HOST_PYTHON
282environment variable must point to a Python interpreter (at least 2.4),
283to support cross-compilation from Win32. Note that Visual Studio
Zachary Waree08f3762014-03-28 23:31:04 -0500284requires Professional Edition or better in order to build 64-bit
Tim Golden7d052362013-10-25 08:58:16 +0100285binaries.
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000286
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000287
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000288Profile Guided Optimization
289---------------------------
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000290
Christian Heimes25bb7832008-01-11 16:17:00 +0000291The solution has two configurations for PGO. The PGInstrument
Tim Golden7d052362013-10-25 08:58:16 +0100292configuration must be built first. The PGInstrument binaries are linked
293against a profiling library and contain extra debug information. The
294PGUpdate configuration takes the profiling data and generates optimized
295binaries.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000296
Tim Golden7d052362013-10-25 08:58:16 +0100297The build_pgo.bat script automates the creation of optimized binaries.
298It creates the PGI files, runs the unit test suite or PyBench with the
299PGI python, and finally creates the optimized files.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000300
Tim Golden7d052362013-10-25 08:58:16 +0100301See
302 http://msdn.microsoft.com/en-us/library/e7k32f4k(VS.100).aspx
303for more on this topic.
304
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000305
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000306Static library
307--------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000308
Tim Golden7d052362013-10-25 08:58:16 +0100309The solution has no configuration for static libraries. However it is
310easy to build a static library instead of a DLL. You simply have to set
311the "Configuration Type" to "Static Library (.lib)" and alter the
312preprocessor macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may
313also have to change the "Runtime Library" from "Multi-threaded DLL
314(/MD)" to "Multi-threaded (/MT)".
315
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000316
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000317Visual Studio properties
318------------------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000319
Tim Golden7d052362013-10-25 08:58:16 +0100320The PCbuild solution makes heavy use of Visual Studio property files
321(*.props). The properties can be viewed and altered in the Property
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000322Manager (View -> Other Windows -> Property Manager).
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000323
Tim Golden7d052362013-10-25 08:58:16 +0100324The property files used are (+-- = "also imports"):
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000325 * debug (debug macro: _DEBUG)
326 * pginstrument (PGO)
327 * pgupdate (PGO)
328 +-- pginstrument
329 * pyd (python extension, release build)
330 +-- release
331 +-- pyproject
332 * pyd_d (python extension, debug build)
333 +-- debug
334 +-- pyproject
335 * pyproject (base settings for all projects, user macros like PyDllName)
336 * release (release macro: NDEBUG)
Tim Golden7d052362013-10-25 08:58:16 +0100337 * sqlite3 (used only by sqlite3.vcxproj)
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000338 * x64 (AMD64 / x64 platform specific settings)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000339
Tim Golden7d052362013-10-25 08:58:16 +0100340The pyproject property file defines _WIN32 and x64 defines _WIN64 and
341_M_X64 although the macros are set by the compiler, too. The GUI doesn't
342always know about the macros and confuse the user with false
343information.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000344
Tim Golden7d052362013-10-25 08:58:16 +0100345
346Your Own Extension DLLs
Tim Peters4b5fb072000-07-01 00:03:43 +0000347-----------------------
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000348
Tim Golden7d052362013-10-25 08:58:16 +0100349If you want to create your own extension module DLL (.pyd), there's an
350example with easy-to-follow instructions in ..\PC\example\; read the
351file readme.txt there first.