getting_started.html 58 KB

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