windows.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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, Simplified Build From Source
  142. --------------------------------
  143. If you wish to build from source with Visual C++, you can use a
  144. simple build procedure described in this section. Open the command prompt
  145. and change your current directory to the Boost root directory. Then, type
  146. the following commands::
  147. bootstrap
  148. .\bjam
  149. The first command prepares the Boost.Build system for use. The second
  150. command invokes Boost.Build to build the separately-compiled Boost
  151. libraries. Please consult the `Boost.Build documentation`__ for a list
  152. of options that can be passed to ``bjam``.
  153. __ http://www.boost.org/boost-build2/doc/html/bbv2/advanced/invocation.html
  154. Or, Build Binaries From Source
  155. ------------------------------
  156. If you're using an earlier version of Visual C++, or a compiler
  157. from another vendor, you'll need to use Boost.Build_ to create your
  158. own binaries.
  159. .. include:: detail/build-from-source-head.rst
  160. For example, your session might look like this: [#continuation]_
  161. .. parsed-literal::
  162. C:\\WINDOWS> cd |default-root|
  163. |default-root|> bjam **^**
  164. More? **--build-dir=**\ "C:\\Documents and Settings\\dave\\build-boost" **^**
  165. More? **--build-type=complete** **msvc** stage
  166. Be sure to read `this note`__ about the appearance of ``^``,
  167. ``More?`` and quotation marks (``"``) in that line.
  168. The option “\ **--build-type=complete**\ ” causes ``bjam`` to build
  169. all supported variants of the libraries. For instructions on how to
  170. build only specific variants, please ask on the `Boost.Build mailing
  171. list`_.
  172. __ continuation_
  173. .. include:: detail/build-from-source-tail.rst
  174. .. _auto-linking:
  175. .. include:: detail/link-head.rst
  176. .. Admonition:: Auto-Linking
  177. Most Windows compilers and linkers have so-called “auto-linking
  178. support,” which eliminates the second challenge. Special code in
  179. Boost header files detects your compiler options and uses that
  180. information to encode the name of the correct library into your
  181. object files; the linker selects the library with that name from
  182. the directories you've told it to search.
  183. The GCC toolchains (Cygwin and MinGW) are notable exceptions;
  184. GCC users should refer to the `linking instructions for Unix
  185. variant OSes`__ for the appropriate command-line options to use.
  186. __ unix-variants.html#link-your-program-to-a-boost-library
  187. Link From Within the Visual Studio IDE
  188. --------------------------------------
  189. Starting with the `header-only example project`__ we created
  190. earlier:
  191. __ vs-header-only_
  192. 1. Right-click **example** in the *Solution Explorer* pane and
  193. select *Properties* from the resulting pop-up menu
  194. 2. In *Configuration Properties* > *Linker* > *Additional Library
  195. Directories*, enter the path to the Boost binaries,
  196. e.g. |default-root|\ ``\lib\``.
  197. 3. From the *Build* menu, select *Build Solution*.
  198. |next|__
  199. __ `Test Your Program`_
  200. Or, Link From the Command Prompt
  201. --------------------------------
  202. For example, we can compile and link the above program from the
  203. Visual C++ command-line by simply adding the **bold** text below to
  204. the command line we used earlier, assuming your Boost binaries are
  205. in |default-root|\ ``\lib``:
  206. .. parsed-literal::
  207. cl /EHsc /I |root| example.cpp **^**
  208. **/link /LIBPATH:** |default-root-bold|\ **\\lib**
  209. Library Naming
  210. --------------
  211. .. Note:: If, like Visual C++, your compiler supports auto-linking,
  212. you can probably |next|__.
  213. __ `Test Your Program`_
  214. .. include:: detail/library-naming.rst
  215. .. include:: detail/test-head.rst
  216. Now, in a `command prompt`_ window, type:
  217. .. parsed-literal::
  218. *path*\ \\\ *to*\ \\\ *compiled*\ \\example < *path*\ \\\ *to*\ \\\ jayne.txt
  219. The program should respond with the email subject, “Will Success
  220. Spoil Rock Hunter?”
  221. .. include:: detail/conclusion.rst
  222. ------------------------------
  223. .. [#zip] We recommend
  224. downloading |boost.7z|_ and using 7-Zip_ to decompress
  225. it. We no longer recommend .zip files for Boost because they are twice
  226. as large as the equivalent .7z files. We don't recommend using Windows'
  227. built-in decompression as it can be painfully slow for large archives.
  228. .. _7-Zip: http://www.7-zip.org
  229. .. [#installer-src] If you used the installer_ from Boost
  230. Consulting and deselected “Source and Documentation” (it's
  231. selected by default), you won't see the ``libs/`` subdirectory.
  232. That won't affect your ability to use precompiled binaries, but
  233. you won't be able to rebuild libraries from scratch.
  234. .. [#pch] There's no problem using Boost with precompiled headers;
  235. these instructions merely avoid precompiled headers because it
  236. would require Visual Studio-specific changes to the source code
  237. used in the examples.
  238. .. [#continuation] In this example, the caret character ``^`` is a
  239. way of continuing the command on multiple lines, and must be the
  240. **final character** used on the line to be continued (i.e. do
  241. not follow it with spaces). The command prompt responds with
  242. ``More?`` to prompt for more input. Feel free to omit the
  243. carets and subsequent newlines; we used them so the example
  244. would fit on a page of reasonable width.
  245. The command prompt treats each bit of whitespace in the command
  246. as an argument separator. That means quotation marks (``"``)
  247. are required to keep text together whenever a single
  248. command-line argument contains spaces, as in
  249. .. parsed-literal::
  250. --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>`
  251. Also, for example, you can't add spaces around the ``=`` sign as in
  252. .. parsed-literal::
  253. --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"
  254. .. |boost.zip| replace:: |boost_ver|\ ``.zip``
  255. .. _`boost.zip`: `sf-download`_
  256. .. |build-type-complete| replace:: **--build-type=complete**
  257. .. include:: detail/common-footnotes.rst
  258. .. include:: detail/release-variables.rst
  259. .. include:: detail/common-windows.rst
  260. .. include:: detail/links.rst
粤ICP备19079148号