gooderp18绿色标准版
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

294 lines
22KB

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>17.1. Building with Visual C++ or the Microsoft Windows SDK</title><link rel="stylesheet" type="text/css" href="stylesheet.css" /><link rev="made" href="pgsql-docs@lists.postgresql.org" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><link rel="prev" href="install-windows.html" title="Chapter 17. Installation from Source Code on Windows" /><link rel="next" href="runtime.html" title="Chapter 18. Server Setup and Operation" /></head><body><div xmlns="http://www.w3.org/TR/xhtml1/transitional" class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="5" align="center">17.1. Building with <span xmlns="http://www.w3.org/1999/xhtml" class="productname">Visual C++</span> or the
  3. <span xmlns="http://www.w3.org/1999/xhtml" class="productname">Microsoft Windows SDK</span></th></tr><tr><td width="10%" align="left"><a accesskey="p" href="install-windows.html" title="Chapter 17. Installation from Source Code on Windows">Prev</a> </td><td width="10%" align="left"><a accesskey="u" href="install-windows.html" title="Chapter 17. Installation from Source Code on Windows">Up</a></td><th width="60%" align="center">Chapter 17. Installation from Source Code on <span xmlns="http://www.w3.org/1999/xhtml" class="productname">Windows</span></th><td width="10%" align="right"><a accesskey="h" href="index.html" title="PostgreSQL 12.4 Documentation">Home</a></td><td width="10%" align="right"> <a accesskey="n" href="runtime.html" title="Chapter 18. Server Setup and Operation">Next</a></td></tr></table><hr></hr></div><div class="sect1" id="INSTALL-WINDOWS-FULL"><div class="titlepage"><div><div><h2 class="title" style="clear: both">17.1. Building with <span class="productname">Visual C++</span> or the
  4. <span class="productname">Microsoft Windows SDK</span></h2></div></div></div><div class="toc"><dl class="toc"><dt><span class="sect2"><a href="install-windows-full.html#id-1.6.4.8.8">17.1.1. Requirements</a></span></dt><dt><span class="sect2"><a href="install-windows-full.html#id-1.6.4.8.9">17.1.2. Special Considerations for 64-Bit Windows</a></span></dt><dt><span class="sect2"><a href="install-windows-full.html#id-1.6.4.8.10">17.1.3. Building</a></span></dt><dt><span class="sect2"><a href="install-windows-full.html#id-1.6.4.8.11">17.1.4. Cleaning and Installing</a></span></dt><dt><span class="sect2"><a href="install-windows-full.html#id-1.6.4.8.12">17.1.5. Running the Regression Tests</a></span></dt></dl></div><p>
  5. PostgreSQL can be built using the Visual C++ compiler suite from Microsoft.
  6. These compilers can be either from <span class="productname">Visual Studio</span>,
  7. <span class="productname">Visual Studio Express</span> or some versions of the
  8. <span class="productname">Microsoft Windows SDK</span>. If you do not already have a
  9. <span class="productname">Visual Studio</span> environment set up, the easiest
  10. ways are to use the compilers from
  11. <span class="productname">Visual Studio 2019</span> or those in the
  12. <span class="productname">Windows SDK 10</span>, which are both free downloads
  13. from Microsoft.
  14. </p><p>
  15. Both 32-bit and 64-bit builds are possible with the Microsoft Compiler suite.
  16. 32-bit PostgreSQL builds are possible with
  17. <span class="productname">Visual Studio 2013</span> to
  18. <span class="productname">Visual Studio 2019</span>,
  19. as well as standalone Windows SDK releases 8.1a to 10.
  20. 64-bit PostgreSQL builds are supported with
  21. <span class="productname">Microsoft Windows SDK</span> version 8.1a to 10 or
  22. <span class="productname">Visual Studio 2013</span> and above. Compilation
  23. is supported down to <span class="productname">Windows 7</span> and
  24. <span class="productname">Windows Server 2008 R2 SP1</span> when building with
  25. <span class="productname">Visual Studio 2013</span> to
  26. <span class="productname">Visual Studio 2019</span>.
  27. </p><p>
  28. The tools for building using <span class="productname">Visual C++</span> or
  29. <span class="productname">Platform SDK</span> are in the
  30. <code class="filename">src/tools/msvc</code> directory. When building, make sure
  31. there are no tools from <span class="productname">MinGW</span> or
  32. <span class="productname">Cygwin</span> present in your system PATH. Also, make
  33. sure you have all the required Visual C++ tools available in the PATH. In
  34. <span class="productname">Visual Studio</span>, start the
  35. <span class="application">Visual Studio Command Prompt</span>.
  36. If you wish to build a 64-bit version, you must use the 64-bit version of
  37. the command, and vice versa.
  38. Starting with <span class="productname">Visual Studio 2017</span> this can be
  39. done from the command line using <code class="command">VsDevCmd.bat</code>, see
  40. <code class="command">-help</code> for the available options and their default values.
  41. <code class="command">vsvars32.bat</code> is available in
  42. <span class="productname">Visual Studio 2015</span> and earlier versions for the
  43. same purpose.
  44. From the <span class="application">Visual Studio Command Prompt</span>, you can
  45. change the targeted CPU architecture, build type, and target OS by using the
  46. <code class="command">vcvarsall.bat</code> command, e.g.
  47. <code class="command">vcvarsall.bat x64 10.0.10240.0</code> to target Windows 10
  48. with a 64-bit release build. See <code class="command">-help</code> for the other
  49. options of <code class="command">vcvarsall.bat</code>. All commands should be run from
  50. the <code class="filename">src\tools\msvc</code> directory.
  51. </p><p>
  52. Before you build, you may need to edit the file <code class="filename">config.pl</code>
  53. to reflect any configuration options you want to change, or the paths to
  54. any third party libraries to use. The complete configuration is determined
  55. by first reading and parsing the file <code class="filename">config_default.pl</code>,
  56. and then apply any changes from <code class="filename">config.pl</code>. For example,
  57. to specify the location of your <span class="productname">Python</span> installation,
  58. put the following in <code class="filename">config.pl</code>:
  59. </p><pre class="programlisting">
  60. $config-&gt;{python} = 'c:\python26';
  61. </pre><p>
  62. You only need to specify those parameters that are different from what's in
  63. <code class="filename">config_default.pl</code>.
  64. </p><p>
  65. If you need to set any other environment variables, create a file called
  66. <code class="filename">buildenv.pl</code> and put the required commands there. For
  67. example, to add the path for bison when it's not in the PATH, create a file
  68. containing:
  69. </p><pre class="programlisting">
  70. $ENV{PATH}=$ENV{PATH} . ';c:\some\where\bison\bin';
  71. </pre><p>
  72. </p><p>
  73. To pass additional command line arguments to the Visual Studio build
  74. command (msbuild or vcbuild):
  75. </p><pre class="programlisting">
  76. $ENV{MSBFLAGS}="/m";
  77. </pre><p>
  78. </p><div class="sect2" id="id-1.6.4.8.8"><div class="titlepage"><div><div><h3 class="title">17.1.1. Requirements</h3></div></div></div><p>
  79. The following additional products are required to build
  80. <span class="productname">PostgreSQL</span>. Use the
  81. <code class="filename">config.pl</code> file to specify which directories the libraries
  82. are available in.
  83. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="productname">Microsoft Windows SDK</span></span></dt><dd><p>
  84. If your build environment doesn't ship with a supported version of the
  85. <span class="productname">Microsoft Windows SDK</span> it
  86. is recommended that you upgrade to the latest version (currently
  87. version 10), available for download from
  88. <a class="ulink" href="https://www.microsoft.com/download" target="_top">https://www.microsoft.com/download</a>.
  89. </p><p>
  90. You must always include the
  91. <span class="application">Windows Headers and Libraries</span> part of the SDK.
  92. If you install a <span class="productname">Windows SDK</span>
  93. including the <span class="application">Visual C++ Compilers</span>,
  94. you don't need <span class="productname">Visual Studio</span> to build.
  95. Note that as of Version 8.0a the Windows SDK no longer ships with a
  96. complete command-line build environment.
  97. </p></dd><dt><span class="term"><span class="productname">ActiveState Perl</span></span></dt><dd><p>
  98. ActiveState Perl is required to run the build generation scripts. MinGW
  99. or Cygwin Perl will not work. It must also be present in the PATH.
  100. Binaries can be downloaded from
  101. <a class="ulink" href="https://www.activestate.com" target="_top">https://www.activestate.com</a>
  102. (Note: version 5.8.3 or later is required,
  103. the free Standard Distribution is sufficient).
  104. </p></dd></dl></div><p>
  105. </p><p>
  106. The following additional products are not required to get started,
  107. but are required to build the complete package. Use the
  108. <code class="filename">config.pl</code> file to specify which directories the libraries
  109. are available in.
  110. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="productname">ActiveState TCL</span></span></dt><dd><p>
  111. Required for building <span class="application">PL/Tcl</span> (Note: version
  112. 8.4 is required, the free Standard Distribution is sufficient).
  113. </p></dd><dt><span class="term"><span class="productname">Bison</span> and
  114. <span class="productname">Flex</span></span></dt><dd><p>
  115. <span class="productname">Bison</span> and <span class="productname">Flex</span> are
  116. required to build from Git, but not required when building from a release
  117. file. Only <span class="productname">Bison</span> 1.875 or versions 2.2 and later
  118. will work. <span class="productname">Flex</span> must be version 2.5.31 or later.
  119. </p><p>
  120. Both <span class="productname">Bison</span> and <span class="productname">Flex</span>
  121. are included in the <span class="productname">msys</span> tool suite, available
  122. from <a class="ulink" href="http://www.mingw.org/wiki/MSYS" target="_top">http://www.mingw.org/wiki/MSYS</a> as part of the
  123. <span class="productname">MinGW</span> compiler suite.
  124. </p><p>
  125. You will need to add the directory containing
  126. <code class="filename">flex.exe</code> and <code class="filename">bison.exe</code> to the
  127. PATH environment variable in <code class="filename">buildenv.pl</code> unless
  128. they are already in PATH. In the case of MinGW, the directory is the
  129. <code class="filename">\msys\1.0\bin</code> subdirectory of your MinGW
  130. installation directory.
  131. </p><div class="note"><h3 class="title">Note</h3><p>
  132. The Bison distribution from GnuWin32 appears to have a bug that
  133. causes Bison to malfunction when installed in a directory with
  134. spaces in the name, such as the default location on English
  135. installations <code class="filename">C:\Program Files\GnuWin32</code>.
  136. Consider installing into <code class="filename">C:\GnuWin32</code> or use the
  137. NTFS short name path to GnuWin32 in your PATH environment setting
  138. (e.g. <code class="filename">C:\PROGRA~1\GnuWin32</code>).
  139. </p></div><div class="note"><h3 class="title">Note</h3><p>
  140. The obsolete <code class="literal">winflex</code> binaries distributed on the PostgreSQL FTP site
  141. and referenced in older documentation will fail with <span class="quote">“<span class="quote">flex: fatal
  142. internal error, exec failed</span>”</span> on 64-bit Windows hosts. Use Flex from
  143. MSYS instead.
  144. </p></div></dd><dt><span class="term"><span class="productname">Diff</span></span></dt><dd><p>
  145. Diff is required to run the regression tests, and can be downloaded
  146. from <a class="ulink" href="http://gnuwin32.sourceforge.net" target="_top">http://gnuwin32.sourceforge.net</a>.
  147. </p></dd><dt><span class="term"><span class="productname">Gettext</span></span></dt><dd><p>
  148. Gettext is required to build with NLS support, and can be downloaded
  149. from <a class="ulink" href="http://gnuwin32.sourceforge.net" target="_top">http://gnuwin32.sourceforge.net</a>. Note that binaries,
  150. dependencies and developer files are all needed.
  151. </p></dd><dt><span class="term"><span class="productname">MIT Kerberos</span></span></dt><dd><p>
  152. Required for GSSAPI authentication support. MIT Kerberos can be
  153. downloaded from
  154. <a class="ulink" href="https://web.mit.edu/Kerberos/dist/index.html" target="_top">https://web.mit.edu/Kerberos/dist/index.html</a>.
  155. </p></dd><dt><span class="term"><span class="productname">libxml2</span> and
  156. <span class="productname">libxslt</span></span></dt><dd><p>
  157. Required for XML support. Binaries can be downloaded from
  158. <a class="ulink" href="https://zlatkovic.com/pub/libxml" target="_top">https://zlatkovic.com/pub/libxml</a> or source from
  159. <a class="ulink" href="http://xmlsoft.org" target="_top">http://xmlsoft.org</a>. Note that libxml2 requires iconv,
  160. which is available from the same download location.
  161. </p></dd><dt><span class="term"><span class="productname">OpenSSL</span></span></dt><dd><p>
  162. Required for SSL support. Binaries can be downloaded from
  163. <a class="ulink" href="https://slproweb.com/products/Win32OpenSSL.html" target="_top">https://slproweb.com/products/Win32OpenSSL.html</a>
  164. or source from <a class="ulink" href="https://www.openssl.org" target="_top">https://www.openssl.org</a>.
  165. </p></dd><dt><span class="term"><span class="productname">ossp-uuid</span></span></dt><dd><p>
  166. Required for UUID-OSSP support (contrib only). Source can be
  167. downloaded from
  168. <a class="ulink" href="http://www.ossp.org/pkg/lib/uuid/" target="_top">http://www.ossp.org/pkg/lib/uuid/</a>.
  169. </p></dd><dt><span class="term"><span class="productname">Python</span></span></dt><dd><p>
  170. Required for building <span class="application">PL/Python</span>. Binaries can
  171. be downloaded from <a class="ulink" href="https://www.python.org" target="_top">https://www.python.org</a>.
  172. </p></dd><dt><span class="term"><span class="productname">zlib</span></span></dt><dd><p>
  173. Required for compression support in <span class="application">pg_dump</span>
  174. and <span class="application">pg_restore</span>. Binaries can be downloaded
  175. from <a class="ulink" href="https://www.zlib.net" target="_top">https://www.zlib.net</a>.
  176. </p></dd></dl></div><p>
  177. </p></div><div class="sect2" id="id-1.6.4.8.9"><div class="titlepage"><div><div><h3 class="title">17.1.2. Special Considerations for 64-Bit Windows</h3></div></div></div><p>
  178. PostgreSQL will only build for the x64 architecture on 64-bit Windows, there
  179. is no support for Itanium processors.
  180. </p><p>
  181. Mixing 32- and 64-bit versions in the same build tree is not supported.
  182. The build system will automatically detect if it's running in a 32- or
  183. 64-bit environment, and build PostgreSQL accordingly. For this reason, it
  184. is important to start the correct command prompt before building.
  185. </p><p>
  186. To use a server-side third party library such as <span class="productname">python</span> or
  187. <span class="productname">OpenSSL</span>, this library <span class="emphasis"><em>must</em></span> also be
  188. 64-bit. There is no support for loading a 32-bit library in a 64-bit
  189. server. Several of the third party libraries that PostgreSQL supports may
  190. only be available in 32-bit versions, in which case they cannot be used with
  191. 64-bit PostgreSQL.
  192. </p></div><div class="sect2" id="id-1.6.4.8.10"><div class="titlepage"><div><div><h3 class="title">17.1.3. Building</h3></div></div></div><p>
  193. To build all of PostgreSQL in release configuration (the default), run the
  194. command:
  195. </p><pre class="screen">
  196. <strong class="userinput"><code>build</code></strong>
  197. </pre><p>
  198. To build all of PostgreSQL in debug configuration, run the command:
  199. </p><pre class="screen">
  200. <strong class="userinput"><code>build DEBUG</code></strong>
  201. </pre><p>
  202. To build just a single project, for example psql, run the commands:
  203. </p><pre class="screen">
  204. <strong class="userinput"><code>build psql</code></strong>
  205. <strong class="userinput"><code>build DEBUG psql</code></strong>
  206. </pre><p>
  207. To change the default build configuration to debug, put the following
  208. in the <code class="filename">buildenv.pl</code> file:
  209. </p><pre class="programlisting">
  210. $ENV{CONFIG}="Debug";
  211. </pre><p>
  212. </p><p>
  213. It is also possible to build from inside the Visual Studio GUI. In this
  214. case, you need to run:
  215. </p><pre class="screen">
  216. <strong class="userinput"><code>perl mkvcbuild.pl</code></strong>
  217. </pre><p>
  218. from the command prompt, and then open the generated
  219. <code class="filename">pgsql.sln</code> (in the root directory of the source tree)
  220. in Visual Studio.
  221. </p></div><div class="sect2" id="id-1.6.4.8.11"><div class="titlepage"><div><div><h3 class="title">17.1.4. Cleaning and Installing</h3></div></div></div><p>
  222. Most of the time, the automatic dependency tracking in Visual Studio will
  223. handle changed files. But if there have been large changes, you may need
  224. to clean the installation. To do this, simply run the
  225. <code class="filename">clean.bat</code> command, which will automatically clean out
  226. all generated files. You can also run it with the
  227. <em class="parameter"><code>dist</code></em> parameter, in which case it will behave like
  228. <strong class="userinput"><code>make distclean</code></strong> and remove the flex/bison output files
  229. as well.
  230. </p><p>
  231. By default, all files are written into a subdirectory of the
  232. <code class="filename">debug</code> or <code class="filename">release</code> directories. To
  233. install these files using the standard layout, and also generate the files
  234. required to initialize and use the database, run the command:
  235. </p><pre class="screen">
  236. <strong class="userinput"><code>install c:\destination\directory</code></strong>
  237. </pre><p>
  238. </p><p>
  239. If you want to install only the client applications and
  240. interface libraries, then you can use these commands:
  241. </p><pre class="screen">
  242. <strong class="userinput"><code>install c:\destination\directory client</code></strong>
  243. </pre><p>
  244. </p></div><div class="sect2" id="id-1.6.4.8.12"><div class="titlepage"><div><div><h3 class="title">17.1.5. Running the Regression Tests</h3></div></div></div><p>
  245. To run the regression tests, make sure you have completed the build of all
  246. required parts first. Also, make sure that the DLLs required to load all
  247. parts of the system (such as the Perl and Python DLLs for the procedural
  248. languages) are present in the system path. If they are not, set it through
  249. the <code class="filename">buildenv.pl</code> file. To run the tests, run one of
  250. the following commands from the <code class="filename">src\tools\msvc</code>
  251. directory:
  252. </p><pre class="screen">
  253. <strong class="userinput"><code>vcregress check</code></strong>
  254. <strong class="userinput"><code>vcregress installcheck</code></strong>
  255. <strong class="userinput"><code>vcregress plcheck</code></strong>
  256. <strong class="userinput"><code>vcregress contribcheck</code></strong>
  257. <strong class="userinput"><code>vcregress modulescheck</code></strong>
  258. <strong class="userinput"><code>vcregress ecpgcheck</code></strong>
  259. <strong class="userinput"><code>vcregress isolationcheck</code></strong>
  260. <strong class="userinput"><code>vcregress bincheck</code></strong>
  261. <strong class="userinput"><code>vcregress recoverycheck</code></strong>
  262. <strong class="userinput"><code>vcregress upgradecheck</code></strong>
  263. </pre><p>
  264. To change the schedule used (default is parallel), append it to the
  265. command line like:
  266. </p><pre class="screen">
  267. <strong class="userinput"><code>vcregress check serial</code></strong>
  268. </pre><p>
  269. For more information about the regression tests, see
  270. <a class="xref" href="regress.html" title="Chapter 32. Regression Tests">Chapter 32</a>.
  271. </p><p>
  272. Running the regression tests on client programs, with
  273. <code class="command">vcregress bincheck</code>, or on recovery tests, with
  274. <code class="command">vcregress recoverycheck</code>, requires an additional Perl module
  275. to be installed:
  276. </p><div class="variablelist"><dl class="variablelist"><dt><span class="term"><span class="productname">IPC::Run</span></span></dt><dd><p>
  277. As of this writing, <code class="literal">IPC::Run</code> is not included in the
  278. ActiveState Perl installation, nor in the ActiveState Perl Package
  279. Manager (PPM) library. To install, download the
  280. <code class="filename">IPC-Run-&lt;version&gt;.tar.gz</code> source archive from CPAN,
  281. at <a class="ulink" href="https://metacpan.org/release/IPC-Run" target="_top">https://metacpan.org/release/IPC-Run</a>, and
  282. uncompress. Edit the <code class="filename">buildenv.pl</code> file, and add a PERL5LIB
  283. variable to point to the <code class="filename">lib</code> subdirectory from the
  284. extracted archive. For example:
  285. </p><pre class="programlisting">
  286. $ENV{PERL5LIB}=$ENV{PERL5LIB} . ';c:\IPC-Run-0.94\lib';
  287. </pre><p>
  288. </p></dd></dl></div><p>
  289. </p></div></div><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="install-windows.html">Prev</a> </td><td width="20%" align="center"><a accesskey="u" href="install-windows.html">Up</a></td><td width="40%" align="right"> <a accesskey="n" href="runtime.html">Next</a></td></tr><tr><td width="40%" align="left" valign="top">Chapter 17. Installation from Source Code on <span class="productname">Windows</span> </td><td width="20%" align="center"><a accesskey="h" href="index.html">Home</a></td><td width="40%" align="right" valign="top"> Chapter 18. Server Setup and Operation</td></tr></table></div></body></html>
上海开阖软件有限公司 沪ICP备12045867号-1