windows.rst 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341
  1. .. Copyright David Abrahams 2006. Distributed under the Boost
  2. .. Software License, Version 1.0. (See accompanying
  3. .. file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
  4. =======================================
  5. |(logo)|__ Getting Started on Windows
  6. =======================================
  7. .. |(logo)| image:: ../../boost.png
  8. :alt: Boost
  9. :class: boost-logo
  10. .. role:: raw-html(raw)
  11. :format: html
  12. __ ../../index.htm
  13. .. section-numbering::
  14. .. Admonition:: A note to Cygwin_ and MinGW_ users
  15. If you plan to use your tools from the Windows command prompt,
  16. you're in the right place. If you plan to build from the Cygwin_
  17. bash shell, you're actually running on a POSIX platform and
  18. should follow the instructions for `getting started on Unix
  19. variants`_. Other command shells, such as MinGW_\ 's MSYS, are
  20. not supported—they may or may not work.
  21. .. _`Getting Started on Unix Variants`: unix-variants.html
  22. .. _Cygwin: http://www.cygwin.com
  23. .. _MinGW: http://mingw.org
  24. .. Contents:: Index
  25. Get Boost
  26. =========
  27. The easiest way to get a copy of Boost is to use the `installer`_
  28. provided by `Boost Consulting`_. We especially recommend this
  29. method if you use Microsoft Visual Studio .NET 2003 or Microsoft
  30. Visual Studio 2005, because the installer can download and install
  31. precompiled library binaries, saving you the trouble of building
  32. them yourself. To complete this tutorial, you'll need to at least
  33. install the Boost.Regex_ binaries when given the option.
  34. .. _installer: http://www.boost-consulting.com/download/windows
  35. .. _Boost Consulting: http://www.boost-consulting.com
  36. If you're using an earlier version of Visual Studio or some other
  37. compiler, or if you prefer to build everything yourself, you can
  38. download |boost.exe|_ and run it to install a complete Boost
  39. distribution. [#zip]_
  40. .. |boost.exe| replace:: |boost_ver|\ ``.exe``
  41. .. _`boost.exe`: `sf-download`_
  42. .. include:: detail/distro.rst
  43. .. include:: detail/header-only.rst
  44. .. include:: detail/build-simple-head.rst
  45. .. _`command prompt`:
  46. .. _`command-line tool`:
  47. .. Note:: To build the examples in this guide, you can use an
  48. Integrated Development Environment (IDE) like Visual Studio, or
  49. you can issue commands from the `command prompt`_. Since every
  50. IDE and compiler has different options and Microsoft's are by
  51. far the dominant compilers on Windows, we only give specific
  52. directions here for Visual Studio 2005 and .NET 2003 IDEs and
  53. their respective command prompt compilers (using the command
  54. prompt is a bit simpler). If you are using another compiler or
  55. IDE, it should be relatively easy to adapt these instructions to
  56. your environment.
  57. .. sidebar:: Command Prompt Basics
  58. :class: small
  59. In Windows, a command-line tool is invoked by typing its name,
  60. optionally followed by arguments, into a *Command Prompt* window
  61. and pressing the Return (or Enter) key.
  62. To open a generic *Command Prompt*, click the *Start* menu
  63. button, click *Run*, type “cmd”, and then click *OK*.
  64. .. _current directory:
  65. All commands are executed within the context of a **current
  66. directory** in the filesystem. To set the current directory,
  67. type:
  68. .. parsed-literal::
  69. cd *path*\ \\\ *to*\ \\\ *some*\ \\\ *directory*
  70. followed by Return. For example,
  71. .. parsed-literal::
  72. cd |default-root|
  73. Long commands can be continued across several lines by typing a
  74. caret (``^``) at the end of all but the last line. Some examples
  75. on this page use that technique to save horizontal space.
  76. .. _vs-header-only:
  77. Build From the Visual Studio IDE
  78. --------------------------------
  79. * From Visual Studio's *File* menu, select *New* > *Project…*
  80. * In the left-hand pane of the resulting *New Project* dialog,
  81. select *Visual C++* > *Win32*.
  82. * In the right-hand pane, select *Win32 Console Application*
  83. (VS8.0) or *Win32 Console Project* (VS7.1).
  84. * In the *name* field, enter “example”
  85. * Right-click **example** in the *Solution Explorer* pane and
  86. select *Properties* from the resulting pop-up menu
  87. * In *Configuration Properties* > *C/C++* > *General* > *Additional Include
  88. Directories*, enter the path to the Boost root directory, for example
  89. |default-root|
  90. * In *Configuration Properties* > *C/C++* > *Precompiled Headers*, change
  91. *Use Precompiled Header (/Yu)* to *Not Using Precompiled
  92. Headers*. [#pch]_
  93. * Replace the contents of the ``example.cpp`` generated by the IDE
  94. with the example code above.
  95. * From the *Build* menu, select *Build Solution*.
  96. To test your application, hit the F5 key and type the following
  97. into the resulting window, followed by the Return key::
  98. 1 2 3
  99. Then hold down the control key and press "Z", followed by the
  100. Return key.
  101. |next|__
  102. __ `Errors and Warnings`_
  103. Or, Build From the Command Prompt
  104. ---------------------------------
  105. From your computer's *Start* menu, if you are a Visual
  106. Studio 2005 user, select
  107. *All Programs* > *Microsoft Visual Studio 2005*
  108. > *Visual Studio Tools* > *Visual Studio 2005 Command Prompt*
  109. or, if you're a Visual Studio .NET 2003 user, select
  110. *All Programs* > *Microsoft Visual Studio .NET 2003*
  111. > *Visual Studio .NET Tools* > *Visual Studio .NET 2003 Command Prompt*
  112. to bring up a special `command prompt`_ window set up for the
  113. Visual Studio compiler. In that window, set the `current
  114. directory`_ to a suitable location for creating some temporary
  115. files and type the following command followed by the Return key:
  116. .. parsed-literal::
  117. cl /EHsc /I |root| *path*\ \\\ *to*\ \\example.cpp
  118. To test the result, type:
  119. .. parsed-literal::
  120. echo 1 2 3 | example
  121. .. include:: detail/errors-and-warnings.rst
  122. .. include:: detail/binary-head.rst
  123. Install Visual Studio (2005 or .NET 2003) Binaries
  124. --------------------------------------------------
  125. The installer_ supplied by Boost Consulting will download and
  126. install pre-compiled binaries into the ``lib\`` subdirectory of the
  127. boost root, typically |default-root|\ ``\lib\``. If you installed
  128. all variants of the Boost.Regex_ binary, you're done with this
  129. step. Otherwise, please run the installer again and install them
  130. now.
  131. |next|__
  132. __ `Link Your Program to a Boost Library`_
  133. Or, Build Binaries From Source
  134. ------------------------------
  135. If you're using an earlier version of Visual C++, or a compiler
  136. from another vendor, you'll need to use Boost.Build_ to create your
  137. own binaries.
  138. .. include:: detail/build-from-source-head.rst
  139. For example, your session might look like this: [#continuation]_
  140. .. parsed-literal::
  141. C:\\WINDOWS> cd |default-root|
  142. |default-root|> bjam **^**
  143. More? **--build-dir=**\ "C:\\Documents and Settings\\dave\\build-boost" **^**
  144. More? **--toolset=**\ msvc stage
  145. Be sure to read `this note`__ about the appearance of ``^``,
  146. ``More?`` and quotation marks (``"``) in that line.
  147. __ continuation_
  148. .. include:: detail/build-from-source-tail.rst
  149. .. _auto-linking:
  150. .. include:: detail/link-head.rst
  151. .. Admonition:: Auto-Linking
  152. Most Windows compilers and linkers have so-called “auto-linking
  153. support,” which eliminates the second challenge. Special code in
  154. Boost header files detects your compiler options and uses that
  155. information to encode the name of the correct library into your
  156. object files; the linker selects the library with that name from
  157. the directories you've told it to search.
  158. The GCC toolchains (Cygwin and MinGW) are notable exceptions;
  159. GCC users should refer to the `linking instructions for Unix
  160. variant OSes`__ for the appropriate command-line options to use.
  161. __ unix-variants.html#link-your-program-to-a-boost-library
  162. Link From Within the Visual Studio IDE
  163. --------------------------------------
  164. Starting with the `header-only example project`__ we created
  165. earlier:
  166. __ vs-header-only_
  167. 1. Right-click **example** in the *Solution Explorer* pane and
  168. select *Properties* from the resulting pop-up menu
  169. 2. In *Configuration Properties* > *Linker* > *Additional Library
  170. Directories*, enter the path to the Boost binaries,
  171. e.g. |default-root|\ ``\lib\``.
  172. 3. From the *Build* menu, select *Build Solution*.
  173. |next|__
  174. __ `Test Your Program`_
  175. Or, Link From the Command Prompt
  176. --------------------------------
  177. For example, we can compile and link the above program from the
  178. Visual C++ command-line by simply adding the **bold** text below to
  179. the command line we used earlier, assuming your Boost binaries are
  180. in |default-root|\ ``\lib``:
  181. .. parsed-literal::
  182. cl /EHsc /I |root| example.cpp **^**
  183. **/link /LIBPATH:** |default-root-bold|\ **\\lib**
  184. Library Naming
  185. --------------
  186. .. Note:: If, like Visual C++, your compiler supports auto-linking,
  187. you can probably |next|__.
  188. __ `Test Your Program`_
  189. .. include:: detail/library-naming.rst
  190. .. include:: detail/test-head.rst
  191. Now, in a `command prompt`_ window, type:
  192. .. parsed-literal::
  193. *path*\ \\\ *to*\ \\\ *compiled*\ \\example < *path*\ \\\ *to*\ \\\ jayne.txt
  194. The program should respond with the email subject, “Will Success
  195. Spoil Rock Hunter?”
  196. .. include:: detail/conclusion.rst
  197. ------------------------------
  198. .. [#zip] If you prefer not to download executable programs,
  199. download |boost.zip|_ and use an external tool to decompress
  200. it. We don't recommend using Windows' built-in decompression as
  201. it can be painfully slow for large archives.
  202. .. [#installer-src] If you used the installer_ from Boost
  203. Consulting and deselected “Source and Documentation” (it's
  204. selected by default), you won't see the ``libs/`` subdirectory.
  205. That won't affect your ability to use precompiled binaries, but
  206. you won't be able to rebuild libraries from scratch.
  207. .. [#pch] There's no problem using Boost with precompiled headers;
  208. these instructions merely avoid precompiled headers because it
  209. would require Visual Studio-specific changes to the source code
  210. used in the examples.
  211. .. [#continuation] In this example, the caret character ``^`` is a
  212. way of continuing the command on multiple lines, and must be the
  213. **final character** used on the line to be continued (i.e. do
  214. not follow it with spaces). The command prompt responds with
  215. ``More?`` to prompt for more input. Feel free to omit the
  216. carets and subsequent newlines; we used them so the example
  217. would fit on a page of reasonable width.
  218. The command prompt treats each bit of whitespace in the command
  219. as an argument separator. That means quotation marks (``"``)
  220. are required to keep text together whenever a single
  221. command-line argument contains spaces, as in
  222. .. parsed-literal::
  223. --build-dir=\ :raw-html:`<strong style="background-color:#B4FFB4">"</strong>`\ C:\\Documents\ :raw-html:`<strong style="color:#B4B4B4; background-color:#B4FFB4">_</strong>`\ and\ :raw-html:`<strong style="color:#B4B4B4; background-color:#B4FFB4">_</strong>`\ Settings\\dave\\build-boost\ \ :raw-html:`<strong style="background-color:#B4FFB4">"</strong>`
  224. Also, for example, you can't add spaces around the ``=`` sign as in
  225. .. parsed-literal::
  226. --build-dir\ :raw-html:`<strong style="color:#B4B4B4; background-color:#FFB4B4">_</strong>`\ =\ :raw-html:`<strong style="color:#B4B4B4; background-color:#FFB4B4">_</strong>`\ "C:\\Documents and Settings\\dave\\build-boost"
  227. .. |boost.zip| replace:: |boost_ver|\ ``.zip``
  228. .. _`boost.zip`: `sf-download`_
  229. .. include:: detail/common-footnotes.rst
  230. .. include:: detail/release-variables.rst
  231. .. include:: detail/common-windows.rst
  232. .. include:: detail/links.rst
粤ICP备19079148号