windows.rst 11 KB

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