windows.rst 9.8 KB

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