windows.html 55 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  6. <meta name="generator" content="Docutils 0.13.1: http://docutils.sourceforge.net/" />
  7. <title>Boost Getting Started on Windows</title>
  8. <link rel="stylesheet" href="../../rst.css" type="text/css" />
  9. </head>
  10. <body>
  11. <div class="document" id="logo-getting-started-on-windows">
  12. <h1 class="title"><a class="reference external" href="../../index.htm"><img alt="Boost" class="boost-logo" src="../../boost.png" /></a> Getting Started on Windows</h1>
  13. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  14. <!-- Software License, Version 1.0. (See accompanying -->
  15. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  16. <div class="admonition admonition-a-note-to-cygwin-and-mingw-users">
  17. <p class="first admonition-title">A note to <a class="reference external" href="http://www.cygwin.com">Cygwin</a> and <a class="reference external" href="http://mingw.org">MinGW</a> users</p>
  18. <p class="last">If you plan to use your tools from the Windows command prompt,
  19. you're in the right place. If you plan to build from the <a class="reference external" href="http://www.cygwin.com">Cygwin</a>
  20. bash shell, you're actually running on a POSIX platform and
  21. should follow the instructions for <a class="reference external" href="unix-variants.html">getting started on Unix
  22. variants</a>. Other command shells, such as <a class="reference external" href="http://mingw.org">MinGW</a>'s MSYS, are
  23. not supported—they may or may not work.</p>
  24. </div>
  25. <div class="contents topic" id="index">
  26. <p class="topic-title first">Index</p>
  27. <ul class="auto-toc simple">
  28. <li><a class="reference internal" href="#get-boost" id="id28">1&nbsp;&nbsp;&nbsp;Get Boost</a></li>
  29. <li><a class="reference internal" href="#the-boost-distribution" id="id29">2&nbsp;&nbsp;&nbsp;The Boost Distribution</a></li>
  30. <li><a class="reference internal" href="#header-only-libraries" id="id30">3&nbsp;&nbsp;&nbsp;Header-Only Libraries</a></li>
  31. <li><a class="reference internal" href="#build-a-simple-program-using-boost" id="id31">4&nbsp;&nbsp;&nbsp;Build a Simple Program Using Boost</a><ul class="auto-toc">
  32. <li><a class="reference internal" href="#build-from-the-visual-studio-ide" id="id32">4.1&nbsp;&nbsp;&nbsp;Build From the Visual Studio IDE</a></li>
  33. <li><a class="reference internal" href="#or-build-from-the-command-prompt" id="id33">4.2&nbsp;&nbsp;&nbsp;Or, Build From the Command Prompt</a></li>
  34. <li><a class="reference internal" href="#errors-and-warnings" id="id34">4.3&nbsp;&nbsp;&nbsp;Errors and Warnings</a></li>
  35. </ul>
  36. </li>
  37. <li><a class="reference internal" href="#prepare-to-use-a-boost-library-binary" id="id35">5&nbsp;&nbsp;&nbsp;Prepare to Use a Boost Library Binary</a><ul class="auto-toc">
  38. <li><a class="reference internal" href="#simplified-build-from-source" id="id36">5.1&nbsp;&nbsp;&nbsp;Simplified Build From Source</a></li>
  39. <li><a class="reference internal" href="#or-build-binaries-from-source" id="id37">5.2&nbsp;&nbsp;&nbsp;Or, Build Binaries From Source</a><ul class="auto-toc">
  40. <li><a class="reference internal" href="#install-boost-build" id="id38">5.2.1&nbsp;&nbsp;&nbsp;Install Boost.Build</a></li>
  41. <li><a class="reference internal" href="#identify-your-toolset" id="id39">5.2.2&nbsp;&nbsp;&nbsp;Identify Your Toolset</a></li>
  42. <li><a class="reference internal" href="#select-a-build-directory" id="id40">5.2.3&nbsp;&nbsp;&nbsp;Select a Build Directory</a></li>
  43. <li><a class="reference internal" href="#invoke-b2" id="id41">5.2.4&nbsp;&nbsp;&nbsp;Invoke <tt class="docutils literal">b2</tt></a></li>
  44. </ul>
  45. </li>
  46. <li><a class="reference internal" href="#expected-build-output" id="id42">5.3&nbsp;&nbsp;&nbsp;Expected Build Output</a></li>
  47. <li><a class="reference internal" href="#in-case-of-build-errors" id="id43">5.4&nbsp;&nbsp;&nbsp;In Case of Build Errors</a></li>
  48. </ul>
  49. </li>
  50. <li><a class="reference internal" href="#link-your-program-to-a-boost-library" id="id44">6&nbsp;&nbsp;&nbsp;Link Your Program to a Boost Library</a><ul class="auto-toc">
  51. <li><a class="reference internal" href="#link-from-within-the-visual-studio-ide" id="id45">6.1&nbsp;&nbsp;&nbsp;Link From Within the Visual Studio IDE</a></li>
  52. <li><a class="reference internal" href="#or-link-from-the-command-prompt" id="id46">6.2&nbsp;&nbsp;&nbsp;Or, Link From the Command Prompt</a></li>
  53. <li><a class="reference internal" href="#library-naming" id="id47">6.3&nbsp;&nbsp;&nbsp;Library Naming</a></li>
  54. <li><a class="reference internal" href="#test-your-program" id="id48">6.4&nbsp;&nbsp;&nbsp;Test Your Program</a></li>
  55. </ul>
  56. </li>
  57. <li><a class="reference internal" href="#conclusion-and-further-resources" id="id49">7&nbsp;&nbsp;&nbsp;Conclusion and Further Resources</a></li>
  58. </ul>
  59. </div>
  60. <div class="section" id="get-boost">
  61. <h1><a class="toc-backref" href="#id28">1&nbsp;&nbsp;&nbsp;Get Boost</a></h1>
  62. <p>The most reliable way to get a copy of Boost is to
  63. download <a class="reference external" href="http://www.boost.org/users/history/version_1_68_0.html"><tt class="docutils literal">boost_1_68_0</tt><tt class="docutils literal">.7z</tt></a> or <a class="reference external" href="http://www.boost.org/users/history/version_1_68_0.html"><tt class="docutils literal">boost_1_68_0</tt><tt class="docutils literal">.zip</tt></a> and unpack it to install a complete Boost
  64. distribution.<a class="footnote-reference" href="#zip" id="id2"><sup>1</sup></a></p>
  65. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  66. <!-- Software License, Version 1.0. (See accompanying -->
  67. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  68. </div>
  69. <div class="section" id="the-boost-distribution">
  70. <h1><a class="toc-backref" href="#id29">2&nbsp;&nbsp;&nbsp;The Boost Distribution</a></h1>
  71. <p>This is a sketch of the resulting directory structure:</p>
  72. <pre class="literal-block">
  73. <strong>boost_1_68_0</strong><strong>\</strong> .................<em>The “boost root directory”</em>
  74. <strong>index.htm</strong> .........<em>A copy of www.boost.org starts here</em>
  75. <strong>boost</strong><strong>\</strong> .........................<em>All Boost Header files</em>
  76. <strong>lib</strong><strong>\</strong> .....................<em>precompiled library binaries</em>
  77. <strong>libs</strong><strong>\</strong> ............<em>Tests, .cpp</em>s<em>, docs, etc., by library</em>
  78. <strong>index.html</strong> ........<em>Library documentation starts here</em>
  79. <strong>algorithm</strong><strong>\</strong>
  80. <strong>any</strong><strong>\</strong>
  81. <strong>array</strong><strong>\</strong>
  82. <em>…more libraries…</em>
  83. <strong>status</strong><strong>\</strong> .........................<em>Boost-wide test suite</em>
  84. <strong>tools</strong><strong>\</strong> ...........<em>Utilities, e.g. Boost.Build, quickbook, bcp</em>
  85. <strong>more</strong><strong>\</strong> ..........................<em>Policy documents, etc.</em>
  86. <strong>doc</strong><strong>\</strong> ...............<em>A subset of all Boost library docs</em>
  87. </pre>
  88. <div class="sidebar">
  89. <p class="first sidebar-title">Header Organization</p>
  90. <p class="pre-wrap">The organization of Boost library headers isn't entirely uniform,
  91. but most libraries follow a few patterns:</p>
  92. <ul class="pre-wrap last">
  93. <li><p class="first">Some older libraries and most very small libraries place all
  94. public headers directly into <tt class="docutils literal">boost</tt><tt class="docutils literal">\</tt>.</p>
  95. </li>
  96. <li><p class="first">Most libraries' public headers live in a subdirectory of
  97. <tt class="docutils literal">boost</tt><tt class="docutils literal">\</tt>, named after the library. For example, you'll find
  98. the Python library's <tt class="docutils literal">def.hpp</tt> header in</p>
  99. <pre class="literal-block">
  100. <tt class="docutils literal">boost</tt><tt class="docutils literal">\</tt><tt class="docutils literal">python</tt><tt class="docutils literal">\</tt><tt class="docutils literal">def.hpp</tt>.
  101. </pre>
  102. </li>
  103. <li><p class="first">Some libraries have an “aggregate header” in <tt class="docutils literal">boost</tt><tt class="docutils literal">\</tt> that
  104. <tt class="docutils literal">#include</tt>s all of the library's other headers. For
  105. example, <a class="reference external" href="../../libs/python/doc/html/building.html">Boost.Python</a>'s aggregate header is</p>
  106. <pre class="literal-block">
  107. <tt class="docutils literal">boost</tt><tt class="docutils literal">\</tt><tt class="docutils literal">python.hpp</tt>.
  108. </pre>
  109. </li>
  110. <li><p class="first">Most libraries place private headers in a subdirectory called
  111. <tt class="docutils literal">detail</tt><tt class="docutils literal">\</tt>, or <tt class="docutils literal">aux_</tt><tt class="docutils literal">\</tt>. Don't expect to find
  112. anything you can use in these directories.</p>
  113. </li>
  114. </ul>
  115. </div>
  116. <p>It's important to note the following:</p>
  117. <ol class="arabic" id="boost-root-directory">
  118. <li><p class="first">The path to the <strong>boost root directory</strong> (often <tt class="docutils literal"><span class="pre">C:\Program</span> Files\boost\</tt><tt class="docutils literal">boost_1_68_0</tt>) is
  119. sometimes referred to as <tt class="docutils literal">$BOOST_ROOT</tt> in documentation and
  120. mailing lists .</p>
  121. </li>
  122. <li><p class="first">To compile anything in Boost, you need a directory containing
  123. the <tt class="docutils literal">boost</tt><tt class="docutils literal">\</tt> subdirectory in your <tt class="docutils literal">#include</tt> path. Specific steps for setting up <tt class="docutils literal">#include</tt>
  124. paths in Microsoft Visual Studio follow later in this document;
  125. if you use another IDE, please consult your product's
  126. documentation for instructions.</p>
  127. </li>
  128. <li><p class="first">Since all of Boost's header files have the <tt class="docutils literal">.hpp</tt> extension,
  129. and live in the <tt class="docutils literal">boost</tt><tt class="docutils literal">\</tt> subdirectory of the boost root, your
  130. Boost <tt class="docutils literal">#include</tt> directives will look like:</p>
  131. <pre class="literal-block">
  132. #include &lt;boost/<em>whatever</em>.hpp&gt;
  133. </pre>
  134. <p>or</p>
  135. <pre class="literal-block">
  136. #include &quot;boost/<em>whatever</em>.hpp&quot;
  137. </pre>
  138. <p>depending on your preference regarding the use of angle bracket
  139. includes. Even Windows users can (and, for
  140. portability reasons, probably should) use forward slashes in
  141. <tt class="docutils literal">#include</tt> directives; your compiler doesn't care.</p>
  142. </li>
  143. <li><p class="first">Don't be distracted by the <tt class="docutils literal">doc</tt><tt class="docutils literal">\</tt> subdirectory; it only
  144. contains a subset of the Boost documentation. Start with
  145. <tt class="docutils literal">libs</tt><tt class="docutils literal">\</tt><tt class="docutils literal">index.html</tt> if you're looking for the whole enchilada.</p>
  146. </li>
  147. </ol>
  148. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  149. <!-- Software License, Version 1.0. (See accompanying -->
  150. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  151. </div>
  152. <div class="section" id="header-only-libraries">
  153. <h1><a class="toc-backref" href="#id30">3&nbsp;&nbsp;&nbsp;Header-Only Libraries</a></h1>
  154. <p>The first thing many people want to know is, “how do I build
  155. Boost?” The good news is that often, there's nothing to build.</p>
  156. <div class="admonition admonition-nothing-to-build">
  157. <p class="first admonition-title">Nothing to Build?</p>
  158. <p class="last">Most Boost libraries are <strong>header-only</strong>: they consist <em>entirely
  159. of header files</em> containing templates and inline functions, and
  160. require no separately-compiled library binaries or special
  161. treatment when linking.</p>
  162. </div>
  163. <!-- .. _separate: -->
  164. <p>The only Boost libraries that <em>must</em> be built separately are:</p>
  165. <ul class="simple">
  166. <li><a class="reference external" href="../../libs/chrono/index.html">Boost.Chrono</a></li>
  167. <li><a class="reference external" href="../../libs/context/index.html">Boost.Context</a></li>
  168. <li><a class="reference external" href="../../libs/filesystem/index.html">Boost.Filesystem</a></li>
  169. <li><a class="reference external" href="../../libs/graph_parallel/index.html">Boost.GraphParallel</a></li>
  170. <li><a class="reference external" href="../../libs/iostreams/index.html">Boost.IOStreams</a></li>
  171. <li><a class="reference external" href="../../libs/locale/index.html">Boost.Locale</a></li>
  172. <li><a class="reference external" href="../../libs/log/index.html">Boost.Log</a> (see <a class="reference external" href="../../libs/log/doc/html/log/installation/config.html">build documentation</a>)</li>
  173. <li><a class="reference external" href="../../libs/mpi/index.html">Boost.MPI</a></li>
  174. <li><a class="reference external" href="../../libs/program_options/index.html">Boost.ProgramOptions</a></li>
  175. <li><a class="reference external" href="../../libs/python/doc/html/building.html">Boost.Python</a> (see the <a class="reference external" href="../../libs/python/doc/html/building.html">Boost.Python build documentation</a>
  176. before building and installing it)</li>
  177. <li><a class="reference external" href="../../libs/regex/index.html">Boost.Regex</a></li>
  178. <li><a class="reference external" href="../../libs/serialization/index.html">Boost.Serialization</a></li>
  179. <li><a class="reference external" href="../../libs/signals/index.html">Boost.Signals</a></li>
  180. <li><a class="reference external" href="../../libs/system/index.html">Boost.System</a></li>
  181. <li><a class="reference external" href="../../libs/thread/index.html">Boost.Thread</a></li>
  182. <li><a class="reference external" href="../../libs/timer/index.html">Boost.Timer</a></li>
  183. <li><a class="reference external" href="../../libs/wave/index.html">Boost.Wave</a></li>
  184. </ul>
  185. <p>A few libraries have optional separately-compiled binaries:</p>
  186. <ul class="simple">
  187. <li><a class="reference external" href="../../libs/date_time/index.html">Boost.DateTime</a> has a binary component that is only needed if
  188. you're using its <tt class="docutils literal">to_string</tt>/<tt class="docutils literal">from_string</tt> or serialization
  189. features, or if you're targeting Visual C++ 6.x or Borland.</li>
  190. <li><a class="reference external" href="../../libs/graph/index.html">Boost.Graph</a> also has a binary component that is only needed if
  191. you intend to <a class="reference external" href="../../libs/graph/doc/read_graphviz.html">parse GraphViz files</a>.</li>
  192. <li><a class="reference external" href="../../libs/math/index.html">Boost.Math</a> has binary components for the TR1 and C99
  193. cmath functions.</li>
  194. <li><a class="reference external" href="../../libs/random/index.html">Boost.Random</a> has a binary component which is only needed if
  195. you're using <tt class="docutils literal">random_device</tt>.</li>
  196. <li><a class="reference external" href="../../libs/test/index.html">Boost.Test</a> can be used in “header-only” or “separately compiled”
  197. mode, although <strong>separate compilation is recommended for serious
  198. use</strong>.</li>
  199. <li><a class="reference external" href="../../libs/exception/index.html">Boost.Exception</a> provides non-intrusive implementation of
  200. exception_ptr for 32-bit _MSC_VER==1310 and _MSC_VER==1400
  201. which requires a separately-compiled binary. This is enabled by
  202. #define BOOST_ENABLE_NON_INTRUSIVE_EXCEPTION_PTR.</li>
  203. </ul>
  204. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  205. <!-- Software License, Version 1.0. (See accompanying -->
  206. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  207. </div>
  208. <div class="section" id="build-a-simple-program-using-boost">
  209. <h1><a class="toc-backref" href="#id31">4&nbsp;&nbsp;&nbsp;Build a Simple Program Using Boost</a></h1>
  210. <p>To keep things simple, let's start by using a header-only library.
  211. The following program reads a sequence of integers from standard
  212. input, uses Boost.Lambda to multiply each number by three, and
  213. writes them to standard output:</p>
  214. <pre class="literal-block">
  215. #include &lt;boost/lambda/lambda.hpp&gt;
  216. #include &lt;iostream&gt;
  217. #include &lt;iterator&gt;
  218. #include &lt;algorithm&gt;
  219. int main()
  220. {
  221. using namespace boost::lambda;
  222. typedef std::istream_iterator&lt;int&gt; in;
  223. std::for_each(
  224. in(std::cin), in(), std::cout &lt;&lt; (_1 * 3) &lt;&lt; &quot; &quot; );
  225. }
  226. </pre>
  227. <p>Copy the text of this program into a file called <tt class="docutils literal">example.cpp</tt>.</p>
  228. <div class="admonition note" id="command-line-tool">
  229. <span id="command-prompt"></span><p class="first admonition-title">Note</p>
  230. <p class="last">To build the examples in this guide, you can use an
  231. Integrated Development Environment (IDE) like Visual Studio, or
  232. you can issue commands from the <a class="reference internal" href="#command-prompt">command prompt</a>. Since every
  233. IDE and compiler has different options and Microsoft's are by
  234. far the dominant compilers on Windows, we only give specific
  235. directions here for Visual Studio 2005 and .NET 2003 IDEs and
  236. their respective command prompt compilers (using the command
  237. prompt is a bit simpler). If you are using another compiler or
  238. IDE, it should be relatively easy to adapt these instructions to
  239. your environment.</p>
  240. </div>
  241. <div class="small sidebar">
  242. <p class="first sidebar-title">Command Prompt Basics</p>
  243. <p>In Windows, a command-line tool is invoked by typing its name,
  244. optionally followed by arguments, into a <em>Command Prompt</em> window
  245. and pressing the Return (or Enter) key.</p>
  246. <p>To open a generic <em>Command Prompt</em>, click the <em>Start</em> menu
  247. button, click <em>Run</em>, type “cmd”, and then click <em>OK</em>.</p>
  248. <p id="current-directory">All commands are executed within the context of a <strong>current
  249. directory</strong> in the filesystem. To set the current directory,
  250. type:</p>
  251. <pre class="literal-block">
  252. cd <em>path</em>\<em>to</em>\<em>some</em>\<em>directory</em>
  253. </pre>
  254. <p>followed by Return. For example,</p>
  255. <pre class="literal-block">
  256. cd <tt class="docutils literal"><span class="pre">C:\Program</span> Files\boost\</tt><tt class="docutils literal">boost_1_68_0</tt>
  257. </pre>
  258. <p class="last">Long commands can be continued across several lines by typing a
  259. caret (<tt class="docutils literal">^</tt>) at the end of all but the last line. Some examples
  260. on this page use that technique to save horizontal space.</p>
  261. </div>
  262. <div class="section" id="build-from-the-visual-studio-ide">
  263. <span id="vs-header-only"></span><h2><a class="toc-backref" href="#id32">4.1&nbsp;&nbsp;&nbsp;Build From the Visual Studio IDE</a></h2>
  264. <ul>
  265. <li><p class="first">From Visual Studio's <em>File</em> menu, select <em>New</em> &gt; <em>Project…</em></p>
  266. </li>
  267. <li><p class="first">In the left-hand pane of the resulting <em>New Project</em> dialog,
  268. select <em>Visual C++</em> &gt; <em>Win32</em>.</p>
  269. </li>
  270. <li><p class="first">In the right-hand pane, select <em>Win32 Console Application</em>
  271. (VS8.0) or <em>Win32 Console Project</em> (VS7.1).</p>
  272. </li>
  273. <li><p class="first">In the <em>name</em> field, enter “example”</p>
  274. </li>
  275. <li><p class="first">Right-click <strong>example</strong> in the <em>Solution Explorer</em> pane and
  276. select <em>Properties</em> from the resulting pop-up menu</p>
  277. </li>
  278. <li><p class="first">In <em>Configuration Properties</em> &gt; <em>C/C++</em> &gt; <em>General</em> &gt; <em>Additional Include
  279. Directories</em>, enter the path to the Boost root directory, for example</p>
  280. <blockquote>
  281. <p><tt class="docutils literal"><span class="pre">C:\Program</span> Files\boost\</tt><tt class="docutils literal">boost_1_68_0</tt></p>
  282. </blockquote>
  283. </li>
  284. <li><p class="first">In <em>Configuration Properties</em> &gt; <em>C/C++</em> &gt; <em>Precompiled Headers</em>, change
  285. <em>Use Precompiled Header (/Yu)</em> to <em>Not Using Precompiled
  286. Headers</em>.<a class="footnote-reference" href="#pch" id="id6"><sup>2</sup></a></p>
  287. </li>
  288. <li><p class="first">Replace the contents of the <tt class="docutils literal">example.cpp</tt> generated by the IDE
  289. with the example code above.</p>
  290. </li>
  291. <li><p class="first">From the <em>Build</em> menu, select <em>Build Solution</em>.</p>
  292. </li>
  293. </ul>
  294. <p>To test your application, hit the F5 key and type the following
  295. into the resulting window, followed by the Return key:</p>
  296. <pre class="literal-block">
  297. 1 2 3
  298. </pre>
  299. <p>Then hold down the control key and press &quot;Z&quot;, followed by the
  300. Return key.</p>
  301. <p><a class="reference internal" href="#errors-and-warnings"><em>skip to the next step</em></a></p>
  302. </div>
  303. <div class="section" id="or-build-from-the-command-prompt">
  304. <h2><a class="toc-backref" href="#id33">4.2&nbsp;&nbsp;&nbsp;Or, Build From the Command Prompt</a></h2>
  305. <p>From your computer's <em>Start</em> menu, if you are a Visual
  306. Studio 2005 user, select</p>
  307. <blockquote>
  308. <em>All Programs</em> &gt; <em>Microsoft Visual Studio 2005</em>
  309. &gt; <em>Visual Studio Tools</em> &gt; <em>Visual Studio 2005 Command Prompt</em></blockquote>
  310. <p>or, if you're a Visual Studio .NET 2003 user, select</p>
  311. <blockquote>
  312. <em>All Programs</em> &gt; <em>Microsoft Visual Studio .NET 2003</em>
  313. &gt; <em>Visual Studio .NET Tools</em> &gt; <em>Visual Studio .NET 2003 Command Prompt</em></blockquote>
  314. <p>to bring up a special <a class="reference internal" href="#command-prompt">command prompt</a> window set up for the
  315. Visual Studio compiler. In that window, set the <a class="reference internal" href="#current-directory">current
  316. directory</a> to a suitable location for creating some temporary
  317. files and type the following command followed by the Return key:</p>
  318. <pre class="literal-block">
  319. cl /EHsc /I <em>path\to\</em><tt class="docutils literal">boost_1_68_0</tt> <em>path</em>\<em>to</em>\example.cpp
  320. </pre>
  321. <p>To test the result, type:</p>
  322. <pre class="literal-block">
  323. echo 1 2 3 | example
  324. </pre>
  325. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  326. <!-- Software License, Version 1.0. (See accompanying -->
  327. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  328. </div>
  329. <div class="section" id="errors-and-warnings">
  330. <h2><a class="toc-backref" href="#id34">4.3&nbsp;&nbsp;&nbsp;Errors and Warnings</a></h2>
  331. <p>Don't be alarmed if you see compiler warnings originating in Boost
  332. headers. We try to eliminate them, but doing so isn't always
  333. practical.<a class="footnote-reference" href="#warnings" id="id8"><sup>4</sup></a> <strong>Errors are another matter</strong>. If you're
  334. seeing compilation errors at this point in the tutorial, check to
  335. be sure you've copied the <a class="reference internal" href="#build-a-simple-program-using-boost">example program</a> correctly and that you've
  336. correctly identified the <a class="reference internal" href="#boost-root-directory">Boost root directory</a>.</p>
  337. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  338. <!-- Software License, Version 1.0. (See accompanying -->
  339. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  340. </div>
  341. </div>
  342. <div class="section" id="prepare-to-use-a-boost-library-binary">
  343. <h1><a class="toc-backref" href="#id35">5&nbsp;&nbsp;&nbsp;Prepare to Use a Boost Library Binary</a></h1>
  344. <p>If you want to use any of the separately-compiled Boost libraries,
  345. you'll need to acquire library binaries.</p>
  346. <div class="section" id="simplified-build-from-source">
  347. <h2><a class="toc-backref" href="#id36">5.1&nbsp;&nbsp;&nbsp;Simplified Build From Source</a></h2>
  348. <p>If you wish to build from source with Visual C++, you can use a
  349. simple build procedure described in this section. Open the command prompt
  350. and change your current directory to the Boost root directory. Then, type
  351. the following commands:</p>
  352. <pre class="literal-block">
  353. bootstrap
  354. .\b2
  355. </pre>
  356. <p>The first command prepares the Boost.Build system for use. The second
  357. command invokes Boost.Build to build the separately-compiled Boost
  358. libraries. Please consult the <a class="reference external" href="http://www.boost.org/build/doc/html/bbv2/overview/invocation.html">Boost.Build documentation</a> for a list
  359. of allowed options.</p>
  360. </div>
  361. <div class="section" id="or-build-binaries-from-source">
  362. <h2><a class="toc-backref" href="#id37">5.2&nbsp;&nbsp;&nbsp;Or, Build Binaries From Source</a></h2>
  363. <p>If you're using an earlier version of Visual C++, or a compiler
  364. from another vendor, you'll need to use <a class="reference external" href="../../tools/build/index.html">Boost.Build</a> to create your
  365. own binaries.</p>
  366. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  367. <!-- Software License, Version 1.0. (See accompanying -->
  368. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  369. <div class="section" id="install-boost-build">
  370. <h3><a class="toc-backref" href="#id38">5.2.1&nbsp;&nbsp;&nbsp;Install Boost.Build</a></h3>
  371. <p><a class="reference external" href="../../tools/build/index.html">Boost.Build</a> is a text-based system for developing, testing, and
  372. installing software. First, you'll need to build and
  373. install it. To do this:</p>
  374. <ol class="arabic simple">
  375. <li>Go to the directory <tt class="docutils literal">tools</tt><tt class="docutils literal">\</tt><tt class="docutils literal">build</tt><tt class="docutils literal">\</tt>.</li>
  376. <li>Run <tt class="docutils literal">bootstrap.bat</tt></li>
  377. <li>Run <tt class="docutils literal">b2 install <span class="pre">--prefix=</span></tt><em>PREFIX</em> where <em>PREFIX</em> is
  378. the directory where you want Boost.Build to be installed</li>
  379. <li>Add <em>PREFIX</em><tt class="docutils literal">\</tt><tt class="docutils literal">bin</tt> to your PATH environment variable.</li>
  380. </ol>
  381. </div>
  382. <div class="section" id="identify-your-toolset">
  383. <span id="toolset-name"></span><span id="toolset"></span><h3><a class="toc-backref" href="#id39">5.2.2&nbsp;&nbsp;&nbsp;Identify Your Toolset</a></h3>
  384. <p>First, find the toolset corresponding to your compiler in the
  385. following table (an up-to-date list is always available <a class="reference external" href="http://www.boost.org/build/doc/html/bbv2/reference/tools.html">in the
  386. Boost.Build documentation</a>).</p>
  387. <div class="admonition note">
  388. <p class="first admonition-title">Note</p>
  389. <p class="last">If you previously chose a toolset for the purposes of
  390. <a class="reference external" href="../../doc/html/bbv2/installation.html">building b2</a>, you should assume it won't work and instead
  391. choose newly from the table below.</p>
  392. </div>
  393. <table border="1" class="docutils">
  394. <colgroup>
  395. <col width="12%" />
  396. <col width="22%" />
  397. <col width="66%" />
  398. </colgroup>
  399. <thead valign="bottom">
  400. <tr><th class="head">Toolset
  401. Name</th>
  402. <th class="head">Vendor</th>
  403. <th class="head">Notes</th>
  404. </tr>
  405. </thead>
  406. <tbody valign="top">
  407. <tr><td><tt class="docutils literal">acc</tt></td>
  408. <td>Hewlett Packard</td>
  409. <td>Only very recent versions are known to work well with Boost</td>
  410. </tr>
  411. <tr><td><tt class="docutils literal">borland</tt></td>
  412. <td>Borland</td>
  413. <td>&nbsp;</td>
  414. </tr>
  415. <tr><td><tt class="docutils literal">como</tt></td>
  416. <td>Comeau Computing</td>
  417. <td>Using this toolset may require <a class="reference external" href="../../tools/build/index.html">configuring</a> another
  418. toolset to act as its backend.</td>
  419. </tr>
  420. <tr><td><tt class="docutils literal">darwin</tt></td>
  421. <td>Apple Computer</td>
  422. <td>Apple's version of the GCC toolchain with support for
  423. Darwin and MacOS X features such as frameworks.</td>
  424. </tr>
  425. <tr><td><tt class="docutils literal">gcc</tt></td>
  426. <td>The Gnu Project</td>
  427. <td>Includes support for Cygwin and MinGW compilers.</td>
  428. </tr>
  429. <tr><td><tt class="docutils literal">hp_cxx</tt></td>
  430. <td>Hewlett Packard</td>
  431. <td>Targeted at the Tru64 operating system.</td>
  432. </tr>
  433. <tr><td><tt class="docutils literal">intel</tt></td>
  434. <td>Intel</td>
  435. <td>&nbsp;</td>
  436. </tr>
  437. <tr><td><tt class="docutils literal">msvc</tt></td>
  438. <td>Microsoft</td>
  439. <td>&nbsp;</td>
  440. </tr>
  441. <tr><td><tt class="docutils literal">sun</tt></td>
  442. <td>Oracle</td>
  443. <td>Only very recent versions are known to work well with
  444. Boost. Note that the Oracle/Sun compiler has a large number
  445. of options which effect binary compatibility: it is vital
  446. that the libraries are built with the same options that your
  447. appliction will use. In particular be aware that the default
  448. standard library may not work well with Boost, <em>unless you
  449. are building for C++11</em>. The particular compiler options you
  450. need can be injected with the b2 command line options
  451. <tt class="docutils literal"><span class="pre">cxxflags=``and</span> ``linkflags=</tt>. For example to build with
  452. the Apache standard library in C++03 mode use
  453. <tt class="docutils literal">b2 <span class="pre">cxxflags=-library=stdcxx4</span> <span class="pre">linkflags=-library=stdcxx4</span></tt>.</td>
  454. </tr>
  455. <tr><td><tt class="docutils literal">vacpp</tt></td>
  456. <td>IBM</td>
  457. <td>The VisualAge C++ compiler.</td>
  458. </tr>
  459. </tbody>
  460. </table>
  461. <p>If you have multiple versions of a particular compiler installed,
  462. you can append the version number to the toolset name, preceded by
  463. a hyphen, e.g. <tt class="docutils literal"><span class="pre">intel-9.0</span></tt> or
  464. <tt class="docutils literal"><span class="pre">borland-5.4.3</span></tt>. <strong>On Windows, append a version
  465. number even if you only have one version installed</strong> (unless you
  466. are using the msvc or gcc toolsets, which have special version
  467. detection code) or <a class="reference internal" href="#auto-linking">auto-linking</a> will fail.</p>
  468. </div>
  469. <div class="section" id="select-a-build-directory">
  470. <span id="id13"></span><span id="build-directory"></span><h3><a class="toc-backref" href="#id40">5.2.3&nbsp;&nbsp;&nbsp;Select a Build Directory</a></h3>
  471. <p><a class="reference external" href="../../tools/build/index.html">Boost.Build</a> will place all intermediate files it generates while
  472. building into the <strong>build directory</strong>. If your Boost root
  473. directory is writable, this step isn't strictly necessary: by
  474. default Boost.Build will create a <tt class="docutils literal">bin.v2/</tt> subdirectory for that
  475. purpose in your current working directory.</p>
  476. </div>
  477. <div class="section" id="invoke-b2">
  478. <h3><a class="toc-backref" href="#id41">5.2.4&nbsp;&nbsp;&nbsp;Invoke <tt class="docutils literal">b2</tt></a></h3>
  479. <p>Change your current directory to the Boost root directory and
  480. invoke <tt class="docutils literal">b2</tt> as follows:</p>
  481. <pre class="literal-block">
  482. b2 <strong>--build-dir=</strong><a class="reference internal" href="#id13"><em>build-directory</em></a> <strong>toolset=</strong><a class="reference internal" href="#toolset-name"><em>toolset-name</em></a> <strong>--build-type=complete</strong> stage
  483. </pre>
  484. <p>For a complete description of these and other invocation options,
  485. please see the <a class="reference external" href="http://www.boost.org/build/doc/html/bbv2/overview/invocation.html">Boost.Build documentation</a>.</p>
  486. <p>For example, your session might look like this:<a class="footnote-reference" href="#continuation" id="id15"><sup>3</sup></a></p>
  487. <pre class="literal-block">
  488. C:\WINDOWS&gt; cd <tt class="docutils literal"><span class="pre">C:\Program</span> Files\boost\</tt><tt class="docutils literal">boost_1_68_0</tt>
  489. <tt class="docutils literal"><span class="pre">C:\Program</span> Files\boost\</tt><tt class="docutils literal">boost_1_68_0</tt>&gt; b2 <strong>^</strong>
  490. More? <strong>--build-dir=</strong>&quot;C:\Documents and Settings\dave\build-boost&quot; <strong>^</strong>
  491. More? <strong>--build-type=complete</strong> <strong>msvc</strong> stage
  492. </pre>
  493. <p>Be sure to read <a class="reference internal" href="#continuation">this note</a> about the appearance of <tt class="docutils literal">^</tt>,
  494. <tt class="docutils literal">More?</tt> and quotation marks (<tt class="docutils literal">&quot;</tt>) in that line.</p>
  495. <p>The option “<strong>--build-type=complete</strong>” causes Boost.Build to build
  496. all supported variants of the libraries. For instructions on how to
  497. build only specific variants, please ask on the <a class="reference external" href="http://www.boost.org/more/mailing_lists.htm#jamboost">Boost.Build mailing
  498. list</a>.</p>
  499. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  500. <!-- Software License, Version 1.0. (See accompanying -->
  501. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  502. <p>Building the special <tt class="docutils literal">stage</tt> target places Boost
  503. library binaries in the <tt class="docutils literal">stage</tt><tt class="docutils literal">\</tt><tt class="docutils literal">lib</tt><tt class="docutils literal">\</tt> subdirectory of
  504. the Boost tree. To use a different directory pass the
  505. <tt class="docutils literal"><span class="pre">--stagedir=</span></tt><em>directory</em> option to <tt class="docutils literal">b2</tt>.</p>
  506. <div class="admonition note">
  507. <p class="first admonition-title">Note</p>
  508. <p class="last"><tt class="docutils literal">b2</tt> is case-sensitive; it is important that all the
  509. parts shown in <strong>bold</strong> type above be entirely lower-case.</p>
  510. </div>
  511. <p>For a description of other options you can pass when invoking
  512. <tt class="docutils literal">b2</tt>, type:</p>
  513. <pre class="literal-block">
  514. b2 --help
  515. </pre>
  516. <p>In particular, to limit the amount of time spent building, you may
  517. be interested in:</p>
  518. <ul class="simple">
  519. <li>reviewing the list of library names with <tt class="docutils literal"><span class="pre">--show-libraries</span></tt></li>
  520. <li>limiting which libraries get built with the <tt class="docutils literal"><span class="pre">--with-</span></tt><em>library-name</em> or <tt class="docutils literal"><span class="pre">--without-</span></tt><em>library-name</em> options</li>
  521. <li>choosing a specific build variant by adding <tt class="docutils literal">release</tt> or
  522. <tt class="docutils literal">debug</tt> to the command line.</li>
  523. </ul>
  524. <div class="admonition note">
  525. <p class="first admonition-title">Note</p>
  526. <p class="last">Boost.Build can produce a great deal of output, which can
  527. make it easy to miss problems. If you want to make sure
  528. everything is went well, you might redirect the output into a
  529. file by appending “<tt class="docutils literal">&gt;build.log <span class="pre">2&gt;&amp;1</span></tt>” to your command line.</p>
  530. </div>
  531. </div>
  532. </div>
  533. <div class="section" id="expected-build-output">
  534. <h2><a class="toc-backref" href="#id42">5.3&nbsp;&nbsp;&nbsp;Expected Build Output</a></h2>
  535. <p>During the process of building Boost libraries, you can expect to
  536. see some messages printed on the console. These may include</p>
  537. <ul>
  538. <li><p class="first">Notices about Boost library configuration—for example, the Regex
  539. library outputs a message about ICU when built without Unicode
  540. support, and the Python library may be skipped without error (but
  541. with a notice) if you don't have Python installed.</p>
  542. </li>
  543. <li><p class="first">Messages from the build tool that report the number of targets
  544. that were built or skipped. Don't be surprised if those numbers
  545. don't make any sense to you; there are many targets per library.</p>
  546. </li>
  547. <li><p class="first">Build action messages describing what the tool is doing, which
  548. look something like:</p>
  549. <pre class="literal-block">
  550. <em>toolset-name</em>.c++ <em>long</em>/<em>path</em>/<em>to</em>/<em>file</em>/<em>being</em>/<em>built</em>
  551. </pre>
  552. </li>
  553. <li><p class="first">Compiler warnings.</p>
  554. </li>
  555. </ul>
  556. </div>
  557. <div class="section" id="in-case-of-build-errors">
  558. <h2><a class="toc-backref" href="#id43">5.4&nbsp;&nbsp;&nbsp;In Case of Build Errors</a></h2>
  559. <p>The only error messages you see when building Boost—if any—should
  560. be related to the IOStreams library's support of zip and bzip2
  561. formats as described <a class="reference external" href="../../libs/iostreams/doc/installation.html">here</a>. Install the relevant development
  562. packages for libz and libbz2 if you need those features. Other
  563. errors when building Boost libraries are cause for concern.</p>
  564. <p>If it seems like the build system can't find your compiler and/or
  565. linker, consider setting up a <tt class="docutils literal"><span class="pre">user-config.jam</span></tt> file as described
  566. <a class="reference external" href="http://www.boost.org/build/doc/html/bbv2/overview/configuration.html">here</a>. If that isn't your problem or the <tt class="docutils literal"><span class="pre">user-config.jam</span></tt> file
  567. doesn't work for you, please address questions about configuring Boost
  568. for your compiler to the <a class="reference external" href="http://www.boost.org/more/mailing_lists.htm#jamboost">Boost.Build mailing list</a>.</p>
  569. <span class="target" id="auto-linking"></span><!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  570. <!-- Software License, Version 1.0. (See accompanying -->
  571. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  572. </div>
  573. </div>
  574. <div class="section" id="link-your-program-to-a-boost-library">
  575. <h1><a class="toc-backref" href="#id44">6&nbsp;&nbsp;&nbsp;Link Your Program to a Boost Library</a></h1>
  576. <p>To demonstrate linking with a Boost binary library, we'll use the
  577. following simple program that extracts the subject lines from
  578. emails. It uses the <a class="reference external" href="../../libs/regex/index.html">Boost.Regex</a> library, which has a
  579. separately-compiled binary component.</p>
  580. <pre class="literal-block">
  581. #include &lt;boost/regex.hpp&gt;
  582. #include &lt;iostream&gt;
  583. #include &lt;string&gt;
  584. int main()
  585. {
  586. std::string line;
  587. boost::regex pat( &quot;^Subject: (Re: |Aw: )*(.*)&quot; );
  588. while (std::cin)
  589. {
  590. std::getline(std::cin, line);
  591. boost::smatch matches;
  592. if (boost::regex_match(line, matches, pat))
  593. std::cout &lt;&lt; matches[2] &lt;&lt; std::endl;
  594. }
  595. }
  596. </pre>
  597. <p>There are two main challenges associated with linking:</p>
  598. <ol class="arabic simple">
  599. <li>Tool configuration, e.g. choosing command-line options or IDE
  600. build settings.</li>
  601. <li>Identifying the library binary, among all the build variants,
  602. whose compile configuration is compatible with the rest of your
  603. project.</li>
  604. </ol>
  605. <div class="admonition admonition-auto-linking">
  606. <p class="first admonition-title">Auto-Linking</p>
  607. <p>Most Windows compilers and linkers have so-called “auto-linking
  608. support,” which eliminates the second challenge. Special code in
  609. Boost header files detects your compiler options and uses that
  610. information to encode the name of the correct library into your
  611. object files; the linker selects the library with that name from
  612. the directories you've told it to search.</p>
  613. <p class="last">The GCC toolchains (Cygwin and MinGW) are notable exceptions;
  614. GCC users should refer to the <a class="reference external" href="unix-variants.html#link-your-program-to-a-boost-library">linking instructions for Unix
  615. variant OSes</a> for the appropriate command-line options to use.</p>
  616. </div>
  617. <div class="section" id="link-from-within-the-visual-studio-ide">
  618. <h2><a class="toc-backref" href="#id45">6.1&nbsp;&nbsp;&nbsp;Link From Within the Visual Studio IDE</a></h2>
  619. <p>Starting with the <a class="reference internal" href="#vs-header-only">header-only example project</a> we created
  620. earlier:</p>
  621. <ol class="arabic simple">
  622. <li>Right-click <strong>example</strong> in the <em>Solution Explorer</em> pane and
  623. select <em>Properties</em> from the resulting pop-up menu</li>
  624. <li>In <em>Configuration Properties</em> &gt; <em>Linker</em> &gt; <em>Additional Library
  625. Directories</em>, enter the path to the Boost binaries,
  626. e.g. <tt class="docutils literal"><span class="pre">C:\Program</span> Files\boost\</tt><tt class="docutils literal">boost_1_68_0</tt><tt class="docutils literal">\lib\</tt>.</li>
  627. <li>From the <em>Build</em> menu, select <em>Build Solution</em>.</li>
  628. </ol>
  629. <p><a class="reference internal" href="#test-your-program"><em>skip to the next step</em></a></p>
  630. </div>
  631. <div class="section" id="or-link-from-the-command-prompt">
  632. <h2><a class="toc-backref" href="#id46">6.2&nbsp;&nbsp;&nbsp;Or, Link From the Command Prompt</a></h2>
  633. <p>For example, we can compile and link the above program from the
  634. Visual C++ command-line by simply adding the <strong>bold</strong> text below to
  635. the command line we used earlier, assuming your Boost binaries are
  636. in <tt class="docutils literal"><span class="pre">C:\Program</span> Files\boost\</tt><tt class="docutils literal">boost_1_68_0</tt><tt class="docutils literal">\lib</tt>:</p>
  637. <pre class="literal-block">
  638. cl /EHsc /I <em>path\to\</em><tt class="docutils literal">boost_1_68_0</tt> example.cpp <strong>^</strong>
  639. <strong>/link /LIBPATH:</strong><strong>C:\Program Files\boost\</strong><strong>boost_1_68_0</strong><strong>\lib</strong>
  640. </pre>
  641. </div>
  642. <div class="section" id="library-naming">
  643. <h2><a class="toc-backref" href="#id47">6.3&nbsp;&nbsp;&nbsp;Library Naming</a></h2>
  644. <div class="admonition note">
  645. <p class="first admonition-title">Note</p>
  646. <p>If, like Visual C++, your compiler supports auto-linking,
  647. you can probably <a class="reference internal" href="#test-your-program"><em>skip to the next step</em></a>.</p>
  648. <blockquote class="last">
  649. </blockquote>
  650. </div>
  651. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  652. <!-- Software License, Version 1.0. (See accompanying -->
  653. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  654. <p>In order to choose the right binary for your build configuration
  655. you need to know how Boost binaries are named. Each library
  656. filename is composed of a common sequence of elements that describe
  657. how it was built. For example,
  658. <tt class="docutils literal"><span class="pre">libboost_regex-vc71-mt-d-x86-1_34.lib</span></tt> can be broken down into the
  659. following elements:</p>
  660. <dl class="docutils">
  661. <dt><tt class="docutils literal">lib</tt></dt>
  662. <dd><em>Prefix</em>: except on Microsoft Windows, every Boost library
  663. name begins with this string. On Windows, only ordinary static
  664. libraries use the <tt class="docutils literal">lib</tt> prefix; import libraries and DLLs do
  665. not.<a class="footnote-reference" href="#distinct" id="id23"><sup>5</sup></a></dd>
  666. <dt><tt class="docutils literal">boost_regex</tt></dt>
  667. <dd><em>Library name</em>: all boost library filenames begin with <tt class="docutils literal">boost_</tt>.</dd>
  668. <dt><tt class="docutils literal"><span class="pre">-vc71</span></tt></dt>
  669. <dd><em>Toolset tag</em>: identifies the <a class="reference internal" href="#toolset">toolset</a> and version used to build
  670. the binary.</dd>
  671. <dt><tt class="docutils literal"><span class="pre">-mt</span></tt></dt>
  672. <dd><em>Threading tag</em>: indicates that the library was
  673. built with multithreading support enabled. Libraries built
  674. without multithreading support can be identified by the absence
  675. of <tt class="docutils literal"><span class="pre">-mt</span></tt>.</dd>
  676. <dt><tt class="docutils literal"><span class="pre">-d</span></tt></dt>
  677. <dd><p class="first"><em>ABI tag</em>: encodes details that affect the library's
  678. interoperability with other compiled code. For each such
  679. feature, a single letter is added to the tag:</p>
  680. <blockquote>
  681. <table border="1" class="docutils">
  682. <colgroup>
  683. <col width="5%" />
  684. <col width="75%" />
  685. <col width="20%" />
  686. </colgroup>
  687. <thead valign="bottom">
  688. <tr><th class="head">Key</th>
  689. <th class="head">Use this library when:</th>
  690. <th class="head">Boost.Build option</th>
  691. </tr>
  692. </thead>
  693. <tbody valign="top">
  694. <tr><td><tt class="docutils literal">s</tt></td>
  695. <td>linking statically to the C++ standard library and compiler runtime support
  696. libraries.</td>
  697. <td>runtime-link=static</td>
  698. </tr>
  699. <tr><td><tt class="docutils literal">g</tt></td>
  700. <td>using debug versions of the standard and runtime support libraries.</td>
  701. <td>runtime-debugging=on</td>
  702. </tr>
  703. <tr><td><tt class="docutils literal">y</tt></td>
  704. <td>using a special <a class="reference external" href="../../libs/python/doc/html/building/python_debugging_builds.html">debug build of Python</a>.</td>
  705. <td>python-debugging=on</td>
  706. </tr>
  707. <tr><td><tt class="docutils literal">d</tt></td>
  708. <td>building a debug version of your code.<a class="footnote-reference" href="#debug-abi" id="id24"><sup>6</sup></a></td>
  709. <td>variant=debug</td>
  710. </tr>
  711. <tr><td><tt class="docutils literal">p</tt></td>
  712. <td>using the STLPort standard library rather than the default one supplied with
  713. your compiler.</td>
  714. <td>stdlib=stlport</td>
  715. </tr>
  716. </tbody>
  717. </table>
  718. </blockquote>
  719. <p class="last">For example, if you build a debug version of your code for use
  720. with debug versions of the static runtime library and the
  721. STLPort standard library,
  722. the tag would be: <tt class="docutils literal"><span class="pre">-sgdp</span></tt>. If none of the above apply, the
  723. ABI tag is ommitted.</p>
  724. </dd>
  725. <dt><tt class="docutils literal"><span class="pre">-x86</span></tt></dt>
  726. <dd><p class="first"><em>Architecture and address model tag</em>: in the first letter, encodes the architecture as follows:</p>
  727. <blockquote>
  728. <table border="1" class="docutils">
  729. <colgroup>
  730. <col width="11%" />
  731. <col width="41%" />
  732. <col width="48%" />
  733. </colgroup>
  734. <thead valign="bottom">
  735. <tr><th class="head">Key</th>
  736. <th class="head">Architecture</th>
  737. <th class="head">Boost.Build option</th>
  738. </tr>
  739. </thead>
  740. <tbody valign="top">
  741. <tr><td><tt class="docutils literal">x</tt></td>
  742. <td>x86-32, x86-64</td>
  743. <td>architecture=x86</td>
  744. </tr>
  745. <tr><td><tt class="docutils literal">a</tt></td>
  746. <td>ARM</td>
  747. <td>architecture=arm</td>
  748. </tr>
  749. <tr><td><tt class="docutils literal">i</tt></td>
  750. <td>IA-64</td>
  751. <td>architecture=ia64</td>
  752. </tr>
  753. <tr><td><tt class="docutils literal">s</tt></td>
  754. <td>Sparc</td>
  755. <td>architecture=sparc</td>
  756. </tr>
  757. <tr><td><tt class="docutils literal">m</tt></td>
  758. <td>MIPS/SGI</td>
  759. <td>architecture=mips*</td>
  760. </tr>
  761. <tr><td><tt class="docutils literal">p</tt></td>
  762. <td>RS/6000 &amp; PowerPC</td>
  763. <td>architecture=power</td>
  764. </tr>
  765. </tbody>
  766. </table>
  767. </blockquote>
  768. <p>The two digits following the letter encode the address model as follows:</p>
  769. <blockquote class="last">
  770. <table border="1" class="docutils">
  771. <colgroup>
  772. <col width="13%" />
  773. <col width="40%" />
  774. <col width="47%" />
  775. </colgroup>
  776. <thead valign="bottom">
  777. <tr><th class="head">Key</th>
  778. <th class="head">Address model</th>
  779. <th class="head">Boost.Build option</th>
  780. </tr>
  781. </thead>
  782. <tbody valign="top">
  783. <tr><td><tt class="docutils literal">32</tt></td>
  784. <td>32 bit</td>
  785. <td>address-model=32</td>
  786. </tr>
  787. <tr><td><tt class="docutils literal">64</tt></td>
  788. <td>64 bit</td>
  789. <td>address-model=64</td>
  790. </tr>
  791. </tbody>
  792. </table>
  793. </blockquote>
  794. </dd>
  795. <dt><tt class="docutils literal"><span class="pre">-1_34</span></tt></dt>
  796. <dd><em>Version tag</em>: the full Boost release number, with periods
  797. replaced by underscores. For example, version 1.31.1 would be
  798. tagged as &quot;-1_31_1&quot;.</dd>
  799. <dt><tt class="docutils literal">.lib</tt></dt>
  800. <dd><em>Extension</em>: determined according to the operating system's usual
  801. convention. On most unix-style platforms the extensions are
  802. <tt class="docutils literal">.a</tt> and <tt class="docutils literal">.so</tt> for static libraries (archives) and shared
  803. libraries, respectively. On Windows, <tt class="docutils literal">.dll</tt> indicates a shared
  804. library and <tt class="docutils literal">.lib</tt> indicates a
  805. static or import library. Where supported by toolsets on unix
  806. variants, a full version extension is added (e.g. &quot;.so.1.34&quot;) and
  807. a symbolic link to the library file, named without the trailing
  808. version number, will also be created.</dd>
  809. </dl>
  810. <!-- .. _Boost.Build toolset names: toolset-name_ -->
  811. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  812. <!-- Software License, Version 1.0. (See accompanying -->
  813. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  814. </div>
  815. <div class="section" id="test-your-program">
  816. <h2><a class="toc-backref" href="#id48">6.4&nbsp;&nbsp;&nbsp;Test Your Program</a></h2>
  817. <p>To test our subject extraction, we'll filter the following text
  818. file. Copy it out of your browser and save it as <tt class="docutils literal">jayne.txt</tt>:</p>
  819. <pre class="literal-block">
  820. To: George Shmidlap
  821. From: Rita Marlowe
  822. Subject: Will Success Spoil Rock Hunter?
  823. ---
  824. See subject.
  825. </pre>
  826. <p>Now, in a <a class="reference internal" href="#command-prompt">command prompt</a> window, type:</p>
  827. <pre class="literal-block">
  828. <em>path</em>\<em>to</em>\<em>compiled</em>\example &lt; <em>path</em>\<em>to</em>\jayne.txt
  829. </pre>
  830. <p>The program should respond with the email subject, “Will Success
  831. Spoil Rock Hunter?”</p>
  832. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  833. <!-- Software License, Version 1.0. (See accompanying -->
  834. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  835. </div>
  836. </div>
  837. <div class="section" id="conclusion-and-further-resources">
  838. <h1><a class="toc-backref" href="#id49">7&nbsp;&nbsp;&nbsp;Conclusion and Further Resources</a></h1>
  839. <p>This concludes your introduction to Boost and to integrating it
  840. with your programs. As you start using Boost in earnest, there are
  841. surely a few additional points you'll wish we had covered. One day
  842. we may have a “Book 2 in the Getting Started series” that addresses
  843. them. Until then, we suggest you pursue the following resources.
  844. If you can't find what you need, or there's anything we can do to
  845. make this document clearer, please post it to the <a class="reference external" href="http://www.boost.org/more/mailing_lists.htm#users">Boost Users'
  846. mailing list</a>.</p>
  847. <ul class="simple">
  848. <li><a class="reference external" href="../../tools/build/index.html">Boost.Build reference manual</a></li>
  849. <li><a class="reference external" href="http://www.boost.org/more/mailing_lists.htm#users">Boost Users' mailing list</a></li>
  850. <li><a class="reference external" href="http://www.boost.org/more/mailing_lists.htm#jamboost">Boost.Build mailing list</a></li>
  851. <li><a class="reference external" href="../../libs/index.html">Index of all Boost library documentation</a></li>
  852. </ul>
  853. <div class="admonition admonition-onward">
  854. <p class="first admonition-title">Onward</p>
  855. <blockquote class="epigraph last">
  856. <p>Good luck, and have fun!</p>
  857. <p class="attribution">&mdash;the Boost Developers</p>
  858. </blockquote>
  859. </div>
  860. <hr class="docutils" />
  861. <table class="docutils footnote" frame="void" id="zip" rules="none">
  862. <colgroup><col class="label" /><col /></colgroup>
  863. <tbody valign="top">
  864. <tr><td class="label"><a class="fn-backref" href="#id2">[1]</a></td><td>We recommend
  865. downloading <a class="reference external" href="http://www.boost.org/users/history/version_1_68_0.html"><tt class="docutils literal">boost_1_68_0</tt><tt class="docutils literal">.7z</tt></a> and using <a class="reference external" href="http://www.7-zip.org">7-Zip</a> to decompress
  866. it. We no longer recommend .zip files for Boost because they are twice
  867. as large as the equivalent .7z files. We don't recommend using Windows'
  868. built-in decompression as it can be painfully slow for large archives.</td></tr>
  869. </tbody>
  870. </table>
  871. <table class="docutils footnote" frame="void" id="pch" rules="none">
  872. <colgroup><col class="label" /><col /></colgroup>
  873. <tbody valign="top">
  874. <tr><td class="label"><a class="fn-backref" href="#id6">[2]</a></td><td>There's no problem using Boost with precompiled headers;
  875. these instructions merely avoid precompiled headers because it
  876. would require Visual Studio-specific changes to the source code
  877. used in the examples.</td></tr>
  878. </tbody>
  879. </table>
  880. <table class="docutils footnote" frame="void" id="continuation" rules="none">
  881. <colgroup><col class="label" /><col /></colgroup>
  882. <tbody valign="top">
  883. <tr><td class="label"><a class="fn-backref" href="#id15">[3]</a></td><td><p class="first">In this example, the caret character <tt class="docutils literal">^</tt> is a
  884. way of continuing the command on multiple lines, and must be the
  885. <strong>final character</strong> used on the line to be continued (i.e. do
  886. not follow it with spaces). The command prompt responds with
  887. <tt class="docutils literal">More?</tt> to prompt for more input. Feel free to omit the
  888. carets and subsequent newlines; we used them so the example
  889. would fit on a page of reasonable width.</p>
  890. <p>The command prompt treats each bit of whitespace in the command
  891. as an argument separator. That means quotation marks (<tt class="docutils literal">&quot;</tt>)
  892. are required to keep text together whenever a single
  893. command-line argument contains spaces, as in</p>
  894. <pre class="literal-block">
  895. --build-dir=<span class="raw-html"><strong style="background-color:#B4FFB4">"</strong></span>C:\Documents<span class="raw-html"><strong style="color:#B4B4B4; background-color:#B4FFB4">_</strong></span>and<span class="raw-html"><strong style="color:#B4B4B4; background-color:#B4FFB4">_</strong></span>Settings\dave\build-boost<span class="raw-html"><strong style="background-color:#B4FFB4">"</strong></span>
  896. </pre>
  897. <p>Also, for example, you can't add spaces around the <tt class="docutils literal">=</tt> sign as in</p>
  898. <pre class="last literal-block">
  899. --build-dir<span class="raw-html"><strong style="color:#B4B4B4; background-color:#FFB4B4">_</strong></span>=<span class="raw-html"><strong style="color:#B4B4B4; background-color:#FFB4B4">_</strong></span>&quot;C:\Documents and Settings\dave\build-boost&quot;
  900. </pre>
  901. </td></tr>
  902. </tbody>
  903. </table>
  904. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  905. <!-- Software License, Version 1.0. (See accompanying -->
  906. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  907. <table class="docutils footnote" frame="void" id="warnings" rules="none">
  908. <colgroup><col class="label" /><col /></colgroup>
  909. <tbody valign="top">
  910. <tr><td class="label"><a class="fn-backref" href="#id8">[4]</a></td><td>Remember that warnings are specific to each compiler
  911. implementation. The developer of a given Boost library might
  912. not have access to your compiler. Also, some warnings are
  913. extremely difficult to eliminate in generic code, to the point
  914. where it's not worth the trouble. Finally, some compilers don't
  915. have any source code mechanism for suppressing warnings.</td></tr>
  916. </tbody>
  917. </table>
  918. <table class="docutils footnote" frame="void" id="distinct" rules="none">
  919. <colgroup><col class="label" /><col /></colgroup>
  920. <tbody valign="top">
  921. <tr><td class="label"><a class="fn-backref" href="#id23">[5]</a></td><td>This convention distinguishes the static version of
  922. a Boost library from the import library for an
  923. identically-configured Boost DLL, which would otherwise have the
  924. same name.</td></tr>
  925. </tbody>
  926. </table>
  927. <table class="docutils footnote" frame="void" id="debug-abi" rules="none">
  928. <colgroup><col class="label" /><col /></colgroup>
  929. <tbody valign="top">
  930. <tr><td class="label"><a class="fn-backref" href="#id24">[6]</a></td><td>These libraries were compiled without optimization
  931. or inlining, with full debug symbols enabled, and without
  932. <tt class="docutils literal">NDEBUG</tt> <tt class="docutils literal">#define</tt>d. Although it's true that sometimes
  933. these choices don't affect binary compatibility with other
  934. compiled code, you can't count on that with Boost libraries.</td></tr>
  935. </tbody>
  936. </table>
  937. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  938. <!-- Software License, Version 1.0. (See accompanying -->
  939. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  940. <!-- This file contains all the definitions that need to be updated -->
  941. <!-- for each new release of Boost. -->
  942. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  943. <!-- Software License, Version 1.0. (See accompanying -->
  944. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  945. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  946. <!-- Software License, Version 1.0. (See accompanying -->
  947. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  948. <!-- Copyright David Abrahams 2006. Distributed under the Boost -->
  949. <!-- Software License, Version 1.0. (See accompanying -->
  950. <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) -->
  951. </div>
  952. </div>
  953. </body>
  954. </html>
粤ICP备19079148号