windows.rst 12 KB

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