blob: fb4a456cf89a79d028fff99ce18c8e9ab29735ee [file] [log] [blame]
Kristján Valur Jónssonc45ea9e2012-05-19 21:10:14 +00001Building Python using VC++ 10.0
Christian Heimes5b5e81c2007-12-31 16:14:33 +00002------------------------------
Christian Heimes57dddfb2008-01-02 18:30:52 +00003
Trent Nelson52037272008-04-02 15:06:49 +00004This directory is used to build Python for Win32 and x64 platforms, e.g.
5Windows 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.
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
Christian Heimes5b5e81c2007-12-31 16:14:33 +000030cross compiling x64 builds on a 32bit OS possible the x64 builds require a
3132bit 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 Brandl08a90122012-09-29 09:34:13 +020040their name: python34_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
50You can find build directories for older versions of Visual Studio and
51Visual 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)
60
61
62C RUNTIME
63---------
64
Kristján Valur Jónssonc45ea9e2012-05-19 21:10:14 +000065Visual Studio 2010 uses version 10 of the C runtime (MSVCRT9). The executables
66no longer use the "Side by Side" assemblies used in previous versions of the
67compiler. This simplifies distribution of applications.
68The run time libraries are avalible under the VC/Redist folder of your visual studio
69distribution. For more info, see the Readme in the VC/Redist folder.
Christian Heimes57dddfb2008-01-02 18:30:52 +000070
Tim Peters4b5fb072000-07-01 00:03:43 +000071SUBPROJECTS
72-----------
Tim Peters610a8272000-07-01 02:51:23 +000073These subprojects should build out of the box. Subprojects other than the
Tim Petersbefc97c2001-01-18 19:01:39 +000074main ones (pythoncore, python, pythonw) generally build a DLL (renamed to
Tim Peters610a8272000-07-01 02:51:23 +000075.pyd) from a specific module so that users don't have to load the code
Tim Peters4b5fb072000-07-01 00:03:43 +000076supporting that module unless they import the module.
Guido van Rossume79cf321998-07-07 22:35:03 +000077
Tim Peters97c96402001-01-17 23:23:13 +000078pythoncore
Tim Peters4b5fb072000-07-01 00:03:43 +000079 .dll and .lib
80python
81 .exe
82pythonw
83 pythonw.exe, a variant of python.exe that doesn't pop up a DOS box
84_socket
85 socketmodule.c
Tim Petersd66595f2001-02-04 03:09:53 +000086_testcapi
Tim Petersb16c56f2001-02-02 21:24:51 +000087 tests of the Python C API, run via Lib/test/test_capi.py, and
Tim Petersd66595f2001-02-04 03:09:53 +000088 implemented by module Modules/_testcapimodule.c
Stefan Krah9a2d99e2012-02-25 12:24:21 +010089_testbuffer
90 buffer protocol tests, run via Lib/test/test_buffer.py, and
91 implemented by module Modules/_testbuffer.c
Tim Petersb012a152002-02-13 23:56:46 +000092pyexpat
93 Python wrapper for accelerated XML parsing, which incorporates stable
94 code from the Expat project: http://sourceforge.net/projects/expat/
Tim Peters4b5fb072000-07-01 00:03:43 +000095select
96 selectmodule.c
Tim Peters19f52c22001-01-24 10:07:22 +000097unicodedata
Tim Peters4b5fb072000-07-01 00:03:43 +000098 large tables of Unicode data
Tim Peters4b5fb072000-07-01 00:03:43 +000099winsound
100 play sounds (typically .wav files) under Windows
101
Trent Nelson52037272008-04-02 15:06:49 +0000102Python-controlled subprojects that wrap external projects:
Trent Nelson52037272008-04-02 15:06:49 +0000103_sqlite3
Martin v. Löwis0e74cac2010-12-17 21:04:09 +0000104 Wraps SQLite 3.7.4, which is currently built by sqlite3.vcproj (see below).
Tim Peters4b5fb072000-07-01 00:03:43 +0000105_tkinter
Georg Brandl1158a332009-06-04 09:30:30 +0000106 Wraps the Tk windowing system. Unlike _sqlite3, there's no
Trent Nelson52037272008-04-02 15:06:49 +0000107 corresponding tcltk.vcproj-type project that builds Tcl/Tk from vcproj's
108 within our pcbuild.sln, which means this module expects to find a
109 pre-built Tcl/Tk in either ..\..\tcltk for 32-bit or ..\..\tcltk64 for
110 64-bit (relative to this directory). See below for instructions to build
111 Tcl/Tk.
Antoine Pitrou37dc5f82011-04-03 17:05:46 +0200112_bz2
113 Python wrapper for the libbzip2 compression library. Homepage
114 http://www.bzip.org/
Martin v. Löwisf6f79252006-03-13 13:48:05 +0000115 Download the source from the python.org copy into the dist
116 directory:
117
Martin v. Löwisecc58772012-05-14 13:52:03 +0200118 svn export http://svn.python.org/projects/external/bzip2-1.0.6
Tim Peters077736b2002-11-14 23:24:40 +0000119
Trent Nelson52037272008-04-02 15:06:49 +0000120 ** NOTE: if you use the Tools\buildbot\external(-amd64).bat approach for
121 obtaining external sources then you don't need to manually get the source
122 above via subversion. **
123
Thomas Heller46a007e2003-08-20 18:27:36 +0000124 A custom pre-link step in the bz2 project settings should manage to
Martin v. Löwisecc58772012-05-14 13:52:03 +0200125 build bzip2-1.0.6\libbz2.lib by magic before bz2.pyd (or bz2_d.pyd) is
Thomas Heller46a007e2003-08-20 18:27:36 +0000126 linked in PCbuild\.
127 However, the bz2 project is not smart enough to remove anything under
Martin v. Löwisecc58772012-05-14 13:52:03 +0200128 bzip2-1.0.6\ when you do a clean, so if you want to rebuild bzip2.lib
129 you need to clean up bzip2-1.0.6\ by hand.
Tim Peters077736b2002-11-14 23:24:40 +0000130
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000131 All of this managed to build libbz2.lib in
Martin v. Löwisecc58772012-05-14 13:52:03 +0200132 bzip2-1.0.6\$platform-$configuration\, which the Python project links in.
Nadeem Vawda3ff069e2011-11-30 00:25:06 +0200133_lzma
134 Python wrapper for the liblzma compression library.
135
136 Download the pre-built Windows binaries from http://tukaani.org/xz/, and
137 extract to ..\xz-5.0.3. If you are using a more recent version of liblzma,
138 it will be necessary to rename the directory from xz-<VERSION> to xz-5.0.3.
Tim Petersb0ead4e2002-11-09 04:48:58 +0000139
Mark Hammondf229f9f2002-12-03 05:47:26 +0000140_ssl
Tim Peterse8bcb252002-12-04 02:39:52 +0000141 Python wrapper for the secure sockets library.
Tim Peters4b5fb072000-07-01 00:03:43 +0000142
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000143 Get the source code through
Mark Hammondf229f9f2002-12-03 05:47:26 +0000144
Georg Brandl84fc4ba2013-05-12 19:50:34 +0200145 svn export http://svn.python.org/projects/external/openssl-1.0.1e
Tim Peterse8bcb252002-12-04 02:39:52 +0000146
Trent Nelson52037272008-04-02 15:06:49 +0000147 ** NOTE: if you use the Tools\buildbot\external(-amd64).bat approach for
148 obtaining external sources then you don't need to manually get the source
149 above via subversion. **
150
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000151 Alternatively, get the latest version from http://www.openssl.org.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000152 You can (theoretically) use any version of OpenSSL you like - the
153 build process will automatically select the latest version.
154
Christian Heimesc81549f2013-06-14 15:40:28 +0200155 You must install the NASM assembler 2.10 or newer from
Benjamin Petersone5384b02008-10-04 22:00:42 +0000156 http://nasm.sf.net
Christian Heimesc81549f2013-06-14 15:40:28 +0200157 for x86 builds. Put nasmw.exe anywhere in your PATH. More recent
158 versions of OpenSSL may need a later version of NASM. If OpenSSL's self
159 tests don't pass, you should first try to update NASM and do a full
160 rebuild of OpenSSL.
Georg Brandl0abcbd72010-08-02 19:43:05 +0000161 Note: recent releases of nasm only have nasm.exe. Just rename it to
162 nasmw.exe.
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000163
164 You can also install ActivePerl from
Hirokazu Yamamoto7c3d7092010-10-28 17:57:25 +0000165 http://www.activestate.com/activeperl/
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000166 if you like to use the official sources instead of the files from
167 python's subversion repository. The svn version contains pre-build
168 makefiles and assembly files.
169
170 The build process makes sure that no patented algorithms are included.
171 For now RC5, MDC2 and IDEA are excluded from the build. You may have
172 to manually remove $(OBJ_D)\i_*.obj from ms\nt.mak if the build process
173 complains about missing files or forbidden IDEA. Again the files provided
174 in the subversion repository are already fixed.
Mark Hammondf229f9f2002-12-03 05:47:26 +0000175
176 The MSVC project simply invokes PCBuild/build_ssl.py to perform
Tim Peterse8bcb252002-12-04 02:39:52 +0000177 the build. This Python script locates and builds your OpenSSL
Mark Hammondf229f9f2002-12-03 05:47:26 +0000178 installation, then invokes a simple makefile to build the final .pyd.
179
180 build_ssl.py attempts to catch the most common errors (such as not
181 being able to find OpenSSL sources, or not being able to find a Perl
182 that works with OpenSSL) and give a reasonable error message.
183 If you have a problem that doesn't seem to be handled correctly
184 (eg, you know you have ActivePerl but we can't find it), please take
185 a peek at build_ssl.py and suggest patches. Note that build_ssl.py
186 should be able to be run directly from the command-line.
187
Tim Peterse8bcb252002-12-04 02:39:52 +0000188 build_ssl.py/MSVC isn't clever enough to clean OpenSSL - you must do
189 this by hand.
Tim Peters4b5fb072000-07-01 00:03:43 +0000190
Trent Nelson52037272008-04-02 15:06:49 +0000191The subprojects above wrap external projects Python doesn't control, and as
192such, a little more work is required in order to download the relevant source
193files for each project before they can be built. The buildbots do this each
194time they're built, so the easiest approach is to run either external.bat or
195external-amd64.bat in the ..\Tools\buildbot directory from ..\, i.e.:
196
197 C:\..\svn.python.org\projects\python\trunk\PCbuild>cd ..
198 C:\..\svn.python.org\projects\python\trunk>Tools\buildbot\external.bat
199
200This extracts all the external subprojects from http://svn.python.org/external
201via Subversion (so you'll need an svn.exe on your PATH) and places them in
202..\.. (relative to this directory). The external(-amd64).bat scripts will
203also build a debug build of Tcl/Tk; there aren't any equivalent batch files
204for building release versions of Tcl/Tk lying around in the Tools\buildbot
205directory. If you need to build a release version of Tcl/Tk it isn't hard
206though, take a look at the relevant external(-amd64).bat file and find the
207two nmake lines, then call each one without the 'DEBUG=1' parameter, i.e.:
208
209The external-amd64.bat file contains this for tcl:
210 nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 DEBUG=1 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
211
212So for a release build, you'd call it as:
213 nmake -f makefile.vc COMPILERFLAGS=-DWINVER=0x0500 MACHINE=AMD64 INSTALLDIR=..\..\tcltk64 clean all install
214
215 XXX Should we compile with OPTS=threads?
216 XXX Our installer copies a lot of stuff out of the Tcl/Tk install
217 XXX directory. Is all of that really needed for Python use of Tcl/Tk?
218
219This will be cleaned up in the future; ideally Tcl/Tk will be brought into our
220pcbuild.sln as custom .vcproj files, just as we've recently done with the
Georg Brandl1158a332009-06-04 09:30:30 +0000221sqlite3.vcproj file, which will remove the need for Tcl/Tk to be built
222separately via a batch file.
Trent Nelson52037272008-04-02 15:06:49 +0000223
224XXX trent.nelson 02-Apr-08:
225 Having the external subprojects in ..\.. relative to this directory is a
226 bit of a nuisance when you're working on py3k and trunk in parallel and
227 your directory layout mimics that of Python's subversion layout, e.g.:
228
229 C:\..\svn.python.org\projects\python\trunk
230 C:\..\svn.python.org\projects\python\branches\py3k
231 C:\..\svn.python.org\projects\python\branches\release25-maint
232
233 I'd like to change things so that external subprojects are fetched from
234 ..\external instead of ..\.., then provide some helper scripts or batch
235 files that would set up a new ..\external directory with svn checkouts of
236 the relevant branches in http://svn.python.org/projects/external/, or
237 alternatively, use junctions to link ..\external with a pre-existing
238 externals directory being used by another branch. i.e. if I'm usually
239 working on trunk (and have previously created trunk\external via the
240 provided batch file), and want to do some work on py3k, I'd set up a
241 junction as follows (using the directory structure above as an example):
242
243 C:\..\python\trunk\external <- already exists and has built versions
244 of the external subprojects
245
246 C:\..\python\branches\py3k>linkd.exe external ..\..\trunk\external
247 Link created at: external
248
249 Only a slight tweak would be needed to the buildbots such that bots
250 building trunk and py3k could make use of the same facility. (2.5.x
251 builds need to be kept separate as they're using Visual Studio 7.1.)
252/XXX trent.nelson 02-Apr-08
253
Martin v. Löwis13e50fe2004-07-20 14:37:48 +0000254Building for Itanium
255--------------------
256
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000257NOTE:
258Official support for Itanium builds have been dropped from the build. Please
Christian Heimesa8223142008-02-09 20:58:00 +0000259contact us and provide patches if you are interested in Itanium builds.
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000260
Tim Peterse82b00f2004-08-30 21:14:51 +0000261The project files support a ReleaseItanium configuration which creates
Martin v. Löwis13e50fe2004-07-20 14:37:48 +0000262Win64/Itanium binaries. For this to work, you need to install the Platform
263SDK, in particular the 64-bit support. This includes an Itanium compiler
264(future releases of the SDK likely include an AMD64 compiler as well).
265In addition, you need the Visual Studio plugin for external C compilers,
266from http://sf.net/projects/vsextcomp. The plugin will wrap cl.exe, to
Tim Peterse82b00f2004-08-30 21:14:51 +0000267locate the proper target compiler, and convert compiler options
Ezio Melotti85a86292013-08-17 16:57:41 +0300268accordingly. The project files require at least version 0.9.
Martin v. Löwis13e50fe2004-07-20 14:37:48 +0000269
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000270Building for AMD64
271------------------
272
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000273The build process for AMD64 / x64 is very similar to standard builds. You just
Martin v. Löwis1561bab2008-02-29 19:39:25 +0000274have to set x64 as platform. In addition, the HOST_PYTHON environment variable
275must point to a Python interpreter (at least 2.4), to support cross-compilation.
Martin v. Löwis856bf9a2006-02-14 20:42:55 +0000276
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000277Building Python Using the free MS Toolkit Compiler
278--------------------------------------------------
279
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000280Microsoft has withdrawn the free MS Toolkit Compiler, so this can no longer
281be considered a supported option. Instead you can use the free VS C++ Express
282Edition.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000283
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000284Profile Guided Optimization
285---------------------------
Thomas Wouters0e3f5912006-08-11 14:57:12 +0000286
Christian Heimes25bb7832008-01-11 16:17:00 +0000287The solution has two configurations for PGO. The PGInstrument
288configuration must be build first. The PGInstrument binaries are
289lniked against a profiling library and contain extra debug
290information. The PGUpdate configuration takes the profiling data and
291generates optimized binaries.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000292
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000293The build_pgo.bat script automates the creation of optimized binaries. It
294creates the PGI files, runs the unit test suite or PyBench with the PGI
295python and finally creates the optimized files.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000296
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000297http://msdn2.microsoft.com/en-us/library/e7k32f4k(VS.90).aspx
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000298
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000299Static library
300--------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000301
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000302The solution has no configuration for static libraries. However it is easy
303it build a static library instead of a DLL. You simply have to set the
304"Configuration Type" to "Static Library (.lib)" and alter the preprocessor
305macro "Py_ENABLE_SHARED" to "Py_NO_ENABLE_SHARED". You may also have to
306change the "Runtime Library" from "Multi-threaded DLL (/MD)" to
307"Multi-threaded (/MT)".
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000308
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000309Visual Studio properties
310------------------------
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000311
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000312The PCbuild solution makes heavy use of Visual Studio property files
313(*.vsprops). The properties can be viewed and altered in the Property
314Manager (View -> Other Windows -> Property Manager).
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000315
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000316 * debug (debug macro: _DEBUG)
317 * pginstrument (PGO)
318 * pgupdate (PGO)
319 +-- pginstrument
320 * pyd (python extension, release build)
321 +-- release
322 +-- pyproject
323 * pyd_d (python extension, debug build)
324 +-- debug
325 +-- pyproject
326 * pyproject (base settings for all projects, user macros like PyDllName)
327 * release (release macro: NDEBUG)
328 * x64 (AMD64 / x64 platform specific settings)
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000329
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000330The pyproject propertyfile defines _WIN32 and x64 defines _WIN64 and _M_X64
331although the macros are set by the compiler, too. The GUI doesn't always know
332about the macros and confuse the user with false information.
Thomas Wouters49fd7fa2006-04-21 10:40:58 +0000333
Tim Petersf9a4a6e2000-07-01 20:38:27 +0000334YOUR OWN EXTENSION DLLs
Tim Peters4b5fb072000-07-01 00:03:43 +0000335-----------------------
Christian Heimes5b5e81c2007-12-31 16:14:33 +0000336
Tim Peters4b5fb072000-07-01 00:03:43 +0000337If you want to create your own extension module DLL, there's an example
338with easy-to-follow instructions in ../PC/example/; read the file
339readme.txt there first.