windows.html 57 KB

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