windows.rst 11 KB

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