getting_started.html 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843
  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>Getting Started With Boost Boost</title>
  8. <link rel="stylesheet" href="../rst.css" type="text/css" />
  9. </head>
  10. <body>
  11. <div class="document" id="getting-started-with-boost-logo">
  12. <h1 class="title">Getting Started With Boost <a class="reference" href="../index.htm"><img alt="Boost" src="../boost.png" /></a></h1>
  13. <p>This guide will help you get started using the Boost libraries.
  14. Have fun!</p>
  15. <div class="contents topic">
  16. <p class="topic-title first"><a id="index" name="index">Index</a></p>
  17. <ul class="auto-toc simple">
  18. <li><a class="reference" href="#getting-boost" id="id20" name="id20">1&nbsp;&nbsp;&nbsp;Getting Boost</a></li>
  19. <li><a class="reference" href="#the-structure-of-a-boost-distribution" id="id21" name="id21">2&nbsp;&nbsp;&nbsp;The Structure of a Boost Distribution</a></li>
  20. <li><a class="reference" href="#building-a-simple-boost-program" id="id22" name="id22">3&nbsp;&nbsp;&nbsp;Building a Simple Boost Program</a><ul class="auto-toc">
  21. <li><a class="reference" href="#nix-e-g-unix-linux-macos-cygwin" id="id23" name="id23">3.1&nbsp;&nbsp;&nbsp;*nix (e.g. Unix, Linux, MacOS, Cygwin)</a></li>
  22. <li><a class="reference" href="#microsoft-windows-command-line-using-visual-c" id="id24" name="id24">3.2&nbsp;&nbsp;&nbsp;Microsoft Windows Command-Line using Visual C++</a></li>
  23. <li><a class="reference" href="#visual-studio-net-2003-or-visual-studio-2005" id="id25" name="id25">3.3&nbsp;&nbsp;&nbsp;Visual Studio .NET 2003 or Visual Studio 2005</a></li>
  24. <li><a class="reference" href="#other-compilers-environments" id="id26" name="id26">3.4&nbsp;&nbsp;&nbsp;Other Compilers/Environments</a></li>
  25. </ul>
  26. </li>
  27. <li><a class="reference" href="#getting-boost-library-binaries" id="id27" name="id27">4&nbsp;&nbsp;&nbsp;Getting Boost Library Binaries</a><ul class="auto-toc">
  28. <li><a class="reference" href="#microsoft-visual-c-8-0-or-7-1-visual-studio-2005-net-2003-binaries" id="id28" name="id28">4.1&nbsp;&nbsp;&nbsp;Microsoft Visual C++ 8.0 or 7.1 (Visual Studio 2005/.NET 2003) Binaries</a></li>
  29. <li><a class="reference" href="#nix-e-g-unix-linux-macos-cygwin-binaries" id="id29" name="id29">4.2&nbsp;&nbsp;&nbsp;*nix (e.g. Unix, Linux, MacOS, Cygwin) Binaries</a></li>
  30. <li><a class="reference" href="#id7" id="id30" name="id30">4.3&nbsp;&nbsp;&nbsp;Other Compilers/Environments</a></li>
  31. <li><a class="reference" href="#building-boost-binaries-with-boost-build" id="id31" name="id31">4.4&nbsp;&nbsp;&nbsp;Building Boost Binaries with Boost.Build</a><ul class="auto-toc">
  32. <li><a class="reference" href="#getting-bjam" id="id32" name="id32">4.4.1&nbsp;&nbsp;&nbsp;Getting <tt class="docutils literal"><span class="pre">bjam</span></tt></a></li>
  33. <li><a class="reference" href="#identify-your-toolset" id="id33" name="id33">4.4.2&nbsp;&nbsp;&nbsp;Identify Your Toolset</a></li>
  34. <li><a class="reference" href="#select-a-build-directory" id="id34" name="id34">4.4.3&nbsp;&nbsp;&nbsp;Select a Build Directory</a></li>
  35. <li><a class="reference" href="#invoke-bjam" id="id35" name="id35">4.4.4&nbsp;&nbsp;&nbsp;Invoke <tt class="docutils literal"><span class="pre">bjam</span></tt></a></li>
  36. <li><a class="reference" href="#stage" id="id36" name="id36">4.4.5&nbsp;&nbsp;&nbsp;<tt class="docutils literal"><span class="pre">stage</span></tt></a></li>
  37. <li><a class="reference" href="#select-a-prefix-directory" id="id37" name="id37">4.4.6&nbsp;&nbsp;&nbsp;Select a Prefix Directory</a></li>
  38. </ul>
  39. </li>
  40. </ul>
  41. </li>
  42. <li><a class="reference" href="#linking-a-program-with-a-boost-library" id="id38" name="id38">5&nbsp;&nbsp;&nbsp;Linking A Program with a Boost Library</a><ul class="auto-toc">
  43. <li><a class="reference" href="#microsoft-windows" id="id39" name="id39">5.1&nbsp;&nbsp;&nbsp;Microsoft Windows</a><ul class="auto-toc">
  44. <li><a class="reference" href="#visual-c-command-line" id="id40" name="id40">5.1.1&nbsp;&nbsp;&nbsp;Visual C++ Command Line</a></li>
  45. <li><a class="reference" href="#visual-studio-ide" id="id41" name="id41">5.1.2&nbsp;&nbsp;&nbsp;Visual Studio IDE</a></li>
  46. </ul>
  47. </li>
  48. <li><a class="reference" href="#id13" id="id42" name="id42">5.2&nbsp;&nbsp;&nbsp;*nix (e.g. Unix, Linux, MacOS, Cygwin)</a></li>
  49. <li><a class="reference" href="#library-naming" id="id43" name="id43">5.3&nbsp;&nbsp;&nbsp;Library Naming</a></li>
  50. </ul>
  51. </li>
  52. </ul>
  53. </div>
  54. <!-- ## Update this substitution for each release -->
  55. <div class="section">
  56. <h1><a class="toc-backref" href="#id20" id="getting-boost" name="getting-boost">1&nbsp;&nbsp;&nbsp;Getting Boost</a></h1>
  57. <p>There are basically three ways to get Boost on your system:</p>
  58. <ol class="arabic simple">
  59. <li>Download and run the <a class="reference" href="http://www.boost-consulting.com/download.html">Windows installer</a> supplied by Boost
  60. Consulting (not available for Boost alpha/beta releases).</li>
  61. </ol>
  62. <!-- ## remove the parenthesized note for full releases -->
  63. <ol class="arabic simple" start="2">
  64. <li>or, <a class="reference" href="http://sourceforge.net/project/showfiles.php?group_id=7586&amp;package_id=8041&amp;release_id=376197">download a complete Boost distribution</a> from SourceForge.</li>
  65. </ol>
  66. <!-- ## Update this link for each release -->
  67. <blockquote>
  68. <table class="docutils field-list" frame="void" rules="none">
  69. <col class="field-name" />
  70. <col class="field-body" />
  71. <tbody valign="top">
  72. <tr class="field"><th class="field-name">Windows users:</th><td class="field-body"><p class="first"><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt><tt class="docutils literal"><span class="pre">.exe</span></tt> is a program you can
  73. run to unpack the distribution; if you prefer not to download
  74. executable programs, get <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
  75. external tool to decompress it. We don't recommend using
  76. Windows' built-in decompression as it can be painfully slow
  77. for large archives.</p>
  78. </td>
  79. </tr>
  80. <tr class="field"><th class="field-name">*nix users:</th><td class="field-body"><p class="first">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
  81. directory where you want to put the Boost installation,
  82. execute</p>
  83. <pre class="last literal-block">
  84. tar --bzip2 -xf <em>/path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>.tar.bz2
  85. </pre>
  86. </td>
  87. </tr>
  88. </tbody>
  89. </table>
  90. </blockquote>
  91. <ol class="arabic simple" start="3">
  92. <li>or use a Boost package from RedHat, Debian, or some other
  93. distribution packager. These instructions may not work for you
  94. if you use this method, because other packagers sometimes choose
  95. to break Boost up into several packages or to reorganize the
  96. directory structure of the Boost distribution.<a class="footnote-reference" href="#packagers" id="id3" name="id3"><sup>1</sup></a></li>
  97. </ol>
  98. </div>
  99. <div class="section">
  100. <h1><a class="toc-backref" href="#id21" id="the-structure-of-a-boost-distribution" name="the-structure-of-a-boost-distribution">2&nbsp;&nbsp;&nbsp;The Structure of a Boost Distribution</a></h1>
  101. <p>This is is a sketch of the directory structure you'll get when you
  102. unpack your Boost installation (windows users replace forward
  103. slashes with backslashes):</p>
  104. <pre class="literal-block">
  105. <strong>boost_1_34_0/</strong> .................<em>The “boost root directory”</em>
  106. <strong>index.html</strong> ....................<em>A copy of www.boost.org</em>
  107. <strong>boost/</strong> .........................<em>All Boost Header files</em>
  108. <strong>libs/</strong> ............<em>Tests, .cpp</em>s<em>, docs, etc., by library</em><a class="footnote-reference" href="#installer-src" id="id4" name="id4"><sup>2</sup></a>
  109. <strong>index.html</strong> ........<em>Library documentation starts here</em>
  110. <strong>algorithm/</strong>
  111. <strong>any/</strong>
  112. <strong>array/</strong>
  113. <em>…more libraries…</em>
  114. <strong>status/</strong> .........................<em>Boost-wide test suite</em>
  115. <strong>tools/</strong> ...........<em>Utilities, e.g. bjam, quickbook, bcp</em>
  116. <strong>more/</strong> ..........................<em>Policy documents, etc.</em>
  117. <strong>doc/</strong> ...............<em>A subset of all Boost library docs</em>
  118. </pre>
  119. <div class="sidebar">
  120. <p class="first sidebar-title">Header Organization</p>
  121. <p>The organization of Boost library headers isn't entirely uniform,
  122. but most libraries follow a few patterns:</p>
  123. <ul class="last simple">
  124. <li>Some older libraries and most very small libraries place all
  125. public headers directly into <tt class="docutils literal"><span class="pre">boost/</span></tt>.</li>
  126. <li>Most libraries' public headers live in a subdirectory of
  127. <tt class="docutils literal"><span class="pre">boost/</span></tt> named after the library. For example, you'll find
  128. the Type Traits Library's <tt class="docutils literal"><span class="pre">is_void.hpp</span></tt> header in
  129. <tt class="docutils literal"><span class="pre">boost/type_traits/is_void.hpp</span></tt>.</li>
  130. <li>Some libraries have an “aggregate header” in <tt class="docutils literal"><span class="pre">boost/</span></tt> that
  131. <tt class="docutils literal"><span class="pre">#include</span></tt>s all of the library's other headers. For
  132. example, Boost.Python's aggregate header is
  133. <tt class="docutils literal"><span class="pre">boost/python.hpp</span></tt>.</li>
  134. <li>Most libraries place private headers in a subdirectory called
  135. <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
  136. expect to find anything you can use.</li>
  137. </ul>
  138. </div>
  139. <p>A few things are worth noting right off the bat:</p>
  140. <ol class="arabic">
  141. <li><p class="first">The path to the “boost root directory” is sometimes referred to
  142. as <tt class="docutils literal"><span class="pre">$BOOST_ROOT</span></tt> in documentation and mailing lists. If you
  143. used the Windows installer, that will usually be <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_34_0</span></tt>.</p>
  144. </li>
  145. <li><p class="first">To compile anything in Boost, you need a directory containing
  146. 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
  147. compilers, that means adding</p>
  148. <pre class="literal-block">
  149. -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>
  150. </pre>
  151. <p>to the command line. Specific steps for setting up <tt class="docutils literal"><span class="pre">#include</span></tt>
  152. paths in Microsoft Visual Studio follow later in this document;
  153. if you use another IDE, please consult your product's
  154. documentation for instructions.</p>
  155. </li>
  156. <li><p class="first">Since all of Boost's header files have the <tt class="docutils literal"><span class="pre">.hpp</span></tt> extension,
  157. and live in the <tt class="docutils literal"><span class="pre">boost/</span></tt> subdirectory of the boost root, your
  158. Boost <tt class="docutils literal"><span class="pre">#include</span></tt> directives will look like:</p>
  159. <pre class="literal-block">
  160. #include &lt;boost/<em>whatever</em>.hpp&gt;
  161. </pre>
  162. <p>or</p>
  163. <pre class="literal-block">
  164. #include &quot;boost/<em>whatever</em>.hpp&quot;
  165. </pre>
  166. </li>
  167. </ol>
  168. <blockquote>
  169. depending on your religion as regards the use of angle bracket
  170. includes. Even Windows users can use forward slashes in
  171. <tt class="docutils literal"><span class="pre">#include</span></tt> directives; your compiler doesn't care.</blockquote>
  172. <ol class="arabic simple" start="4">
  173. <li>Don't be distracted by the <tt class="docutils literal"><span class="pre">doc/</span></tt> subdirectory; it only
  174. contains a subset of the Boost documentation. Start with
  175. <tt class="docutils literal"><span class="pre">libs/index.html</span></tt> if you're looking for the whole enchilada.</li>
  176. </ol>
  177. </div>
  178. <div class="section">
  179. <h1><a class="toc-backref" href="#id22" id="building-a-simple-boost-program" name="building-a-simple-boost-program">3&nbsp;&nbsp;&nbsp;Building a Simple Boost Program</a></h1>
  180. <p>The first thing many people want to know is, “how do I build
  181. Boost?” The good news is that often, there's nothing to build.</p>
  182. <div class="admonition-header-only-libraries admonition">
  183. <p class="first admonition-title">Header-Only Libraries</p>
  184. <p>Nearly all Boost libraries are <strong>header-only</strong>. That is, most
  185. consist entirely of header files containing templates and inline
  186. functions, and require no separately-compiled library binaries
  187. or special treatment when linking.</p>
  188. <p>The only Boost libraries that are <em>not</em> header-only are:</p>
  189. <ul class="simple">
  190. <li>Boost.Filesystem</li>
  191. <li>Boost.IOStreams</li>
  192. <li>Boost.ProgramOptions</li>
  193. <li>Boost.Python</li>
  194. <li>Boost.Regex</li>
  195. <li>Boost.Serialization</li>
  196. <li>Boost.Signals</li>
  197. <li>Boost.Test</li>
  198. <li>Boost.Thread</li>
  199. <li>Boost.Wave</li>
  200. </ul>
  201. <p class="last">The DateTime library has a separately-compiled
  202. binary which is only needed if you're using a “legacy
  203. compiler”(such as?). The Graph library has a
  204. separately-compiled binary, but you won't need it unless you
  205. intend to <a class="reference" href="../libs/graph/doc/read_graphviz.html">parse GraphViz files</a>.</p>
  206. </div>
  207. <!-- ## Keep the list of non-header-only libraries up-to-date -->
  208. <p>The following program reads a sequence of integers from standard
  209. input, uses Boost.Lambda (a header-only library) to multiply each
  210. one by three, and writes them to standard output:</p>
  211. <pre class="literal-block">
  212. #include &lt;boost/lambda/lambda.hpp&gt;
  213. #include &lt;iostream&gt;
  214. #include &lt;iterator&gt;
  215. #include &lt;algorithm&gt;
  216. int main()
  217. {
  218. using namespace boost::lambda;
  219. typedef std::istream_iterator&lt;int&gt; in;
  220. std::for_each(
  221. in(std::cin), in(), std::cout &lt;&lt; (_1 * 3) &lt;&lt; &quot; &quot; );
  222. }
  223. </pre>
  224. <p>Start by copying the text of this program into a file called
  225. <tt class="docutils literal"><span class="pre">example.cpp</span></tt>.</p>
  226. <div class="section">
  227. <h2><a class="toc-backref" href="#id23" id="nix-e-g-unix-linux-macos-cygwin" name="nix-e-g-unix-linux-macos-cygwin"><span id="unix-header-only"></span>3.1&nbsp;&nbsp;&nbsp;*nix (e.g. Unix, Linux, MacOS, Cygwin)</a></h2>
  228. <p>Simply issue the following command (<tt class="docutils literal"><span class="pre">$</span></tt> represents the
  229. prompt issued by the shell, so don't type that):</p>
  230. <pre class="literal-block">
  231. <strong>$</strong> 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
  232. </pre>
  233. <p>To test the result, type:</p>
  234. <pre class="literal-block">
  235. <strong>$</strong> echo 1 2 3 | ./example
  236. </pre>
  237. </div>
  238. <div class="section">
  239. <h2><a class="toc-backref" href="#id24" id="microsoft-windows-command-line-using-visual-c" name="microsoft-windows-command-line-using-visual-c">3.2&nbsp;&nbsp;&nbsp;Microsoft Windows Command-Line using Visual C++</a></h2>
  240. <p>From your computer's <em>Start</em> menu, select if you are a Visual
  241. Studio 2005 user, select</p>
  242. <blockquote>
  243. <em>All Programs</em> &gt; <em>Microsoft Visual Studio 2005</em>
  244. &gt; <em>Visual Studio Tools</em> &gt; <em>Visual Studio 2005 Command Prompt</em></blockquote>
  245. <p>or if you're a Visual Studio .NET 2003 user, select</p>
  246. <blockquote>
  247. <em>All Programs</em> &gt; <em>Microsoft Visual Studio .NET 2003</em>
  248. &gt; <em>Visual Studio .NET Tools</em> &gt; <em>Visual Studio .NET 2003 Command Prompt</em></blockquote>
  249. <p>to bring up a special command prompt window set up for the Visual
  250. Studio compiler. In that window, type the following command and
  251. hit the return key (<tt class="docutils literal"><span class="pre">C:\PROMPT&gt;</span></tt> represents the prompt issued by
  252. the shell, so don't type that):</p>
  253. <pre class="literal-block">
  254. <strong>C:PROMPT&gt;</strong> cl /EHsc /I <em>C:</em><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
  255. </pre>
  256. <p>To test the result, type:</p>
  257. <pre class="literal-block">
  258. <strong>C:PROMPT&gt;</strong> echo 1 2 3 | example
  259. </pre>
  260. </div>
  261. <div class="section">
  262. <h2><a class="toc-backref" href="#id25" id="visual-studio-net-2003-or-visual-studio-2005" name="visual-studio-net-2003-or-visual-studio-2005"><span id="vs-header-only"></span>3.3&nbsp;&nbsp;&nbsp;Visual Studio .NET 2003 or Visual Studio 2005</a></h2>
  263. <ul class="simple">
  264. <li>From Visual Studio's <em>File</em> menu, select <em>New</em> &gt; <em>Project…</em></li>
  265. <li>In the left-hand pane of the resulting <em>New Project</em> dialog,
  266. select <em>Visual C++</em> &gt; <em>Win32</em>.</li>
  267. <li>In the right-hand pane, select <em>Win32 Console Application</em>
  268. (VS8.0) or <em>Win32 Console Project</em> (VS7.1).</li>
  269. <li>In the <em>name</em> field, enter “example”</li>
  270. <li>Right-click <strong>example</strong> in the <em>Solution Explorer</em> pane and
  271. select <em>Properties</em> from the resulting pop-up menu</li>
  272. <li>In <em>Configuration Properties</em> &gt; <em>C/C++</em> &gt; <em>General</em> &gt; <em>Additional Include
  273. Directories</em>, enter the path to the Boost root directory, e.g.
  274. <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_34_0</span></tt>.</li>
  275. <li>In <em>Configuration Properties</em> &gt; <em>C/C++</em> &gt; <em>Precompiled Headers</em>, change
  276. <em>Use Precompiled Header (/Yu)</em> to <em>Not Using Precompiled
  277. Headers</em>.<a class="footnote-reference" href="#pch" id="id6" name="id6"><sup>3</sup></a></li>
  278. <li>Replace the contents of the <tt class="docutils literal"><span class="pre">example.cpp</span></tt> generated by the IDE
  279. with the example code above.</li>
  280. <li>From the <em>Build</em> menu, select <em>Build Solution</em>.</li>
  281. </ul>
  282. <p>To test your application, hit the F5 key and type the following
  283. into the resulting window, followed by the return key:</p>
  284. <pre class="literal-block">
  285. 1 2 3
  286. </pre>
  287. <p>Then hold down the control key and press &quot;Z&quot;, followed by the
  288. return key.</p>
  289. </div>
  290. <div class="section">
  291. <h2><a class="toc-backref" href="#id26" id="other-compilers-environments" name="other-compilers-environments">3.4&nbsp;&nbsp;&nbsp;Other Compilers/Environments</a></h2>
  292. <p>Consult your vendor's documentation; if you have trouble adapting
  293. these instructions to your build environment, request assistance on
  294. the <a class="reference" href="mailing_lists.htm#users">Boost Users' mailing list</a>.</p>
  295. </div>
  296. </div>
  297. <div class="section">
  298. <h1><a class="toc-backref" href="#id27" id="getting-boost-library-binaries" name="getting-boost-library-binaries">4&nbsp;&nbsp;&nbsp;Getting Boost Library Binaries</a></h1>
  299. <p>If you want to use any of the separately-compiled Boost libraries,
  300. you'll need to get ahold of library binaries.</p>
  301. <div class="section">
  302. <h2><a class="toc-backref" href="#id28" id="microsoft-visual-c-8-0-or-7-1-visual-studio-2005-net-2003-binaries" name="microsoft-visual-c-8-0-or-7-1-visual-studio-2005-net-2003-binaries">4.1&nbsp;&nbsp;&nbsp;Microsoft Visual C++ 8.0 or 7.1 (Visual Studio 2005/.NET 2003) Binaries</a></h2>
  303. <p>The <a class="reference" href="http://www.boost-consulting.com/download.html">Windows installer</a> supplied by Boost Consulting will download
  304. and install pre-compiled binaries into the <tt class="docutils literal"><span class="pre">lib\</span></tt> subdirectory of
  305. the 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_34_0</span></tt><tt class="docutils literal"><span class="pre">\lib\</span></tt>.</p>
  306. </div>
  307. <div class="section">
  308. <h2><a class="toc-backref" href="#id29" id="nix-e-g-unix-linux-macos-cygwin-binaries" name="nix-e-g-unix-linux-macos-cygwin-binaries">4.2&nbsp;&nbsp;&nbsp;*nix (e.g. Unix, Linux, MacOS, Cygwin) Binaries</a></h2>
  309. <p>Issue the following commands in the shell (again, <tt class="docutils literal"><span class="pre">$</span></tt> represents
  310. the shell's prompt):</p>
  311. <pre class="literal-block">
  312. <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>
  313. <strong>$</strong> ./configure --help
  314. </pre>
  315. <p>Select your configuration options and invoke <tt class="docutils literal"><span class="pre">./configure</span></tt> again.
  316. Unless you have write permission in your system's <tt class="docutils literal"><span class="pre">/usr/local/</span></tt>
  317. directory, you'll probably want to at least use</p>
  318. <pre class="literal-block">
  319. <strong>$</strong> ./configure <strong>--prefix=</strong><em>path</em>/<em>to</em>/<em>installation</em>/<em>prefix</em>
  320. </pre>
  321. <p>to install somewhere else. Finally,</p>
  322. <pre class="literal-block">
  323. <strong>$</strong> make install
  324. </pre>
  325. <p>which will leave Boost binaries in the <tt class="docutils literal"><span class="pre">lib/</span></tt> subdirectory of
  326. your installation prefix. You will also find a copy of the Boost
  327. headers in the <tt class="docutils literal"><span class="pre">include/</span></tt> subdirectory of the installation
  328. prefix, so you can henceforth use that directory as an <tt class="docutils literal"><span class="pre">#include</span></tt>
  329. path in place of the Boost root directory.</p>
  330. </div>
  331. <div class="section">
  332. <h2><a class="toc-backref" href="#id30" id="id7" name="id7">4.3&nbsp;&nbsp;&nbsp;Other Compilers/Environments</a></h2>
  333. <p>If you're not using Visual C++ 7.1 or 8.0, or you're a *nix user
  334. who wants want to build with a toolset other than your system's
  335. default, or if you want a nonstandard variant build of Boost
  336. (e.g. optimized, but with debug symbols), you'll need to use
  337. <a class="reference" href="../tools/build/index.html">Boost.Build</a> to create your own binaries.</p>
  338. </div>
  339. <div class="section">
  340. <h2><a id="building-boost-binaries-with-boost-build" name="building-boost-binaries-with-boost-build">4.4&nbsp;&nbsp;&nbsp;Building Boost Binaries with <a class="reference" href="../tools/build/index.html">Boost.Build</a></a></h2>
  341. <p>Like an IDE, <a class="reference" href="../tools/build/index.html">Boost.Build</a> is a system for developing, testing, and
  342. installing software. Instead of using a GUI, though, <a class="reference" href="../tools/build/index.html">Boost.Build</a>
  343. is text-based, like <tt class="docutils literal"><span class="pre">make</span></tt>. <a class="reference" href="../tools/build/index.html">Boost.Build</a> is written in the
  344. interpreted <a class="reference" href="../tools/jam/index.html">Boost.Jam</a> language.</p>
  345. <p>To use <a class="reference" href="../tools/build/index.html">Boost.Build</a>, you'll need an executable called <tt class="docutils literal"><span class="pre">bjam</span></tt>, the
  346. <a class="reference" href="../tools/jam/index.html">Boost.Jam</a> interpreter.</p>
  347. <!-- nosidebar .. sidebar:: Using Boost.Build for your own project
  348. When you use Boost.Build to build your *own* project, you don't
  349. need a separate step to create Boost binaries: you simply refer
  350. to the boost library targets from your Jamfile and the are built
  351. automatically (refer to the `Boost.Build documentation`_ for
  352. detailed instructions). Here, we're assuming you're using a
  353. different build system for your own code, so you need to
  354. explicitly generate Boost binaries. We're also assuming that
  355. you have a complete Boost distribution somewhere. -->
  356. <div class="section">
  357. <h3><a class="toc-backref" href="#id32" id="getting-bjam" name="getting-bjam">4.4.1&nbsp;&nbsp;&nbsp;Getting <tt class="docutils literal"><span class="pre">bjam</span></tt></a></h3>
  358. <div class="sidebar">
  359. <p class="first sidebar-title">Using command-line tools in Windows</p>
  360. <p>In Windows, a command-line tool is invoked by typing its name,
  361. optionally followed by arguments, into a <em>Command Prompt</em> window
  362. and pressing the Return (or Enter) key.</p>
  363. <p>To open <em>Command Prompt</em>, click the <em>Start</em> menu button, click
  364. <em>Run</em>, type “cmd”, and then click OK.</p>
  365. <p>All commands are executed within the context of a <strong>current
  366. directory</strong> in the filesystem. To set the current directory,
  367. type:</p>
  368. <pre class="literal-block">
  369. cd <em>path</em>\<em>to</em>\<em>some</em>\<em>directory</em>
  370. </pre>
  371. <p>followed by Return. For example,</p>
  372. <pre class="literal-block">
  373. 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_34_0</span></tt>
  374. </pre>
  375. <p>One way to name a directory you know about is to write</p>
  376. <pre class="literal-block">
  377. %HOMEDRIVE%%HOMEPATH%\<em>directory-name</em>
  378. </pre>
  379. <p>which indicates a sibling folder of your “My Documents” folder.</p>
  380. <p class="last">Long commands can be continued across several lines by typing
  381. backslashes at the ends of all but the last line. Many of the
  382. examples on this page use that technique to save horizontal
  383. space.</p>
  384. </div>
  385. <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.
  386. Alternatively, you can build <tt class="docutils literal"><span class="pre">bjam</span></tt> yourself using the
  387. <a class="reference" href="http://www.boost.org/doc/html/jam/building.html">instructions</a> given in the <a class="reference" href="../tools/jam/index.html">Boost.Jam documentation</a>.</p>
  388. <p><tt class="docutils literal"><span class="pre">bjam</span></tt> is a command-line tool. To build Boost binaries, you'll
  389. invoke <tt class="docutils literal"><span class="pre">bjam</span></tt> with the current directory set to the Boost root,
  390. and with options described in the following sections.</p>
  391. </div>
  392. <div class="section">
  393. <h3><a class="toc-backref" href="#id33" id="identify-your-toolset" name="identify-your-toolset"><span id="toolset-name"></span><span id="toolset"></span>4.4.2&nbsp;&nbsp;&nbsp;Identify Your Toolset</a></h3>
  394. <p>First, find the toolset corresponding to your compiler in the
  395. following table.</p>
  396. <table border="1" class="docutils">
  397. <colgroup>
  398. <col width="18%" />
  399. <col width="33%" />
  400. <col width="48%" />
  401. </colgroup>
  402. <thead valign="bottom">
  403. <tr><th class="head">Toolset
  404. Name</th>
  405. <th class="head">Vendor</th>
  406. <th class="head">Notes</th>
  407. </tr>
  408. </thead>
  409. <tbody valign="top">
  410. <tr><td><tt class="docutils literal"><span class="pre">acc</span></tt></td>
  411. <td>Hewlett Packard</td>
  412. <td>Only very recent versions are
  413. known to work well with Boost</td>
  414. </tr>
  415. <tr><td><tt class="docutils literal"><span class="pre">borland</span></tt></td>
  416. <td>Borland</td>
  417. <td>&nbsp;</td>
  418. </tr>
  419. <tr><td><tt class="docutils literal"><span class="pre">como</span></tt></td>
  420. <td>Comeau Computing</td>
  421. <td>Using this toolset may
  422. require <a class="reference" href="../tools/build/index.html">configuring</a> another
  423. toolset to act as its backend</td>
  424. </tr>
  425. <tr><td><tt class="docutils literal"><span class="pre">cw</span></tt></td>
  426. <td>Metrowerks/FreeScale</td>
  427. <td>The CodeWarrior compiler. We
  428. have not tested versions of
  429. this compiler produced since
  430. it was sold to FreeScale.</td>
  431. </tr>
  432. <tr><td><tt class="docutils literal"><span class="pre">dmc</span></tt></td>
  433. <td>Digital Mars</td>
  434. <td>As of this Boost release, no
  435. version of dmc is known to
  436. handle Boost well.</td>
  437. </tr>
  438. <tr><td><tt class="docutils literal"><span class="pre">gcc</span></tt></td>
  439. <td>The Gnu Project</td>
  440. <td>&nbsp;</td>
  441. </tr>
  442. <tr><td><tt class="docutils literal"><span class="pre">hp_cxx</span></tt></td>
  443. <td>Hewlett Packard</td>
  444. <td>Targeted at the Tru64
  445. operating system.</td>
  446. </tr>
  447. <tr><td><tt class="docutils literal"><span class="pre">intel</span></tt></td>
  448. <td>Intel</td>
  449. <td>&nbsp;</td>
  450. </tr>
  451. <tr><td><tt class="docutils literal"><span class="pre">kylix</span></tt></td>
  452. <td>Borland</td>
  453. <td>&nbsp;</td>
  454. </tr>
  455. <tr><td><tt class="docutils literal"><span class="pre">msvc</span></tt></td>
  456. <td>Microsoft</td>
  457. <td>&nbsp;</td>
  458. </tr>
  459. <tr><td><tt class="docutils literal"><span class="pre">qcc</span></tt></td>
  460. <td>QNX Software Systems</td>
  461. <td>&nbsp;</td>
  462. </tr>
  463. <tr><td><tt class="docutils literal"><span class="pre">sun</span></tt></td>
  464. <td>Sun</td>
  465. <td>&nbsp;</td>
  466. </tr>
  467. <tr><td><tt class="docutils literal"><span class="pre">vacpp</span></tt></td>
  468. <td>IBM</td>
  469. <td>The VisualAge C++ compiler.</td>
  470. </tr>
  471. </tbody>
  472. </table>
  473. <p>If you have multiple versions of a particular compiler installed,
  474. you can apend the version number to the toolset name, preceded by a
  475. 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>
  476. <div class="note">
  477. <p class="first admonition-title">Note</p>
  478. <p class="last">if you built <tt class="docutils literal"><span class="pre">bjam</span></tt> yourself, you may
  479. have selected a toolset name for that purpose, but that does not
  480. affect this step in any way; you still need to select a Boost.Build
  481. toolset from the table.</p>
  482. </div>
  483. </div>
  484. <div class="section">
  485. <h3><a class="toc-backref" href="#id34" id="select-a-build-directory" name="select-a-build-directory"><span id="id10"></span><span id="build-directory"></span>4.4.3&nbsp;&nbsp;&nbsp;Select a Build Directory</a></h3>
  486. <p><a class="reference" href="../tools/build/index.html">Boost.Build</a> will place all intermediate files it generates while
  487. building into the <strong>build directory</strong>. If your Boost root
  488. directory is writable, this step isn't strictly necessary: by
  489. default Boost.Build will create a <tt class="docutils literal"><span class="pre">bin.v2/</span></tt> subdirectory for that
  490. purpose in your current working directory.</p>
  491. </div>
  492. <div class="section">
  493. <h3><a class="toc-backref" href="#id35" id="invoke-bjam" name="invoke-bjam">4.4.4&nbsp;&nbsp;&nbsp;Invoke <tt class="docutils literal"><span class="pre">bjam</span></tt></a></h3>
  494. <p>Change your current directory to the Boost root directory and
  495. invoke <tt class="docutils literal"><span class="pre">bjam</span></tt> as follows:</p>
  496. <pre class="literal-block">
  497. bjam --build-dir=<a class="reference" href="#id10"><em>build-directory</em></a> <strong>\</strong>
  498. --toolset=<a class="reference" href="#toolset-name"><em>toolset-name</em></a> stage
  499. </pre>
  500. <p>For example, on Windows, your session might look like:</p>
  501. <pre class="literal-block">
  502. 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_34_0</span></tt>
  503. <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_34_0</span></tt>&gt; bjam <strong>\</strong>
  504. <strong>--build-dir=</strong>%HOMEDRIVE%%HOMEPATH%\build-boost <strong>\</strong>
  505. <strong>--toolset=msvc stage</strong>
  506. </pre>
  507. <div class="note">
  508. <p class="first admonition-title">Note</p>
  509. <p class="last"><tt class="docutils literal"><span class="pre">bjam</span></tt> is case-sensitive; it is important that all the
  510. parts shown in <strong>bold</strong> type above be entirely lower-case.</p>
  511. </div>
  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. ~/<tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>$ bjam --build-dir=~/build-boost --prefix=~/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 <em>build directory</em>.</p>
  519. </div>
  520. <div class="section">
  521. <h3><a class="toc-backref" href="#id36" id="stage" name="stage">4.4.5&nbsp;&nbsp;&nbsp;<tt class="docutils literal"><span class="pre">stage</span></tt></a></h3>
  522. <p>You already have the Boost headers on your system (in the
  523. <tt class="docutils literal"><span class="pre">boost/</span></tt> subdirectory of your Boost distribution), so if you
  524. prefer not to create an additional copy, instead of installing
  525. Boost you can simply “stage” the Boost binaries, which leaves them
  526. in the <tt class="docutils literal"><span class="pre">stage/</span></tt> subdirectory of your chosen <a class="reference" href="#build-directory">build directory</a>:</p>
  527. <pre class="literal-block">
  528. bjam --build-dir=<a class="reference" href="#id10"><em>build-directory</em></a> <strong>\</strong>
  529. --toolset=<a class="reference" href="#toolset-name"><em>toolset-name</em></a> stage
  530. </pre>
  531. </div>
  532. <div class="section">
  533. <h3><a class="toc-backref" href="#id37" id="select-a-prefix-directory" name="select-a-prefix-directory"><span id="id11"></span><span id="prefix-directory"></span>4.4.6&nbsp;&nbsp;&nbsp;Select a Prefix Directory</a></h3>
  534. <p>Choose a <strong>prefix directory</strong>. The installation process will
  535. leave you with the following subdirectories of the prefix directory:</p>
  536. <ul class="simple">
  537. <li><tt class="docutils literal"><span class="pre">lib</span></tt>, containing the Boost binaries</li>
  538. <li><tt class="docutils literal"><span class="pre">include/</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>, containing the Boost headers.</li>
  539. </ul>
  540. <p>Change your current directory to the Boost root directory and
  541. invoke <tt class="docutils literal"><span class="pre">bjam</span></tt> as follows:</p>
  542. <pre class="literal-block">
  543. bjam --build-dir=<a class="reference" href="#id10"><em>build-directory</em></a> <strong>\</strong>
  544. --toolset=<a class="reference" href="#toolset-name"><em>toolset-name</em></a> <strong>\</strong>
  545. --prefix=<a class="reference" href="#id11"><em>prefix-directory</em></a> install
  546. </pre>
  547. <p>For example, on Windows your session might look like:</p>
  548. <pre class="literal-block">
  549. 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_34_0</span></tt>
  550. <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_34_0</span></tt>&gt; bjam <strong>\</strong>
  551. --build-dir=C:\TEMP\build-boost <strong>\</strong>
  552. --prefix=C:\boost
  553. </pre>
  554. <p>And on Unix:</p>
  555. <pre class="literal-block">
  556. ~$ cd ~/<tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>
  557. ~/<tt class="docutils literal"><span class="pre">boost_1_34_0</span></tt>$ bjam --build-dir=/tmp/build-boost <strong>\</strong>
  558. --prefix=~/boost
  559. </pre>
  560. </div>
  561. </div>
  562. </div>
  563. <div class="section">
  564. <h1><a class="toc-backref" href="#id38" id="linking-a-program-with-a-boost-library" name="linking-a-program-with-a-boost-library">5&nbsp;&nbsp;&nbsp;Linking A Program with a Boost Library</a></h1>
  565. <p>To demonstrate linking with a Boost binary library, we'll use the
  566. following simple program that extracts the subject lines from
  567. emails. It uses the <a class="reference" href="../libs/regex">Boost.Regex</a> library, which has a
  568. separately-compiled binary component.</p>
  569. <pre class="literal-block">
  570. #include &lt;boost/regex.hpp&gt;
  571. #include &lt;iostream&gt;
  572. #include &lt;string&gt;
  573. int main()
  574. {
  575. std::string line;
  576. boost::regex pat( &quot;^Subject: (Re: |Aw: )*(.*)&quot; );
  577. while (std::cin)
  578. {
  579. std::getline(std::cin, line);
  580. boost::smatch matches;
  581. if (boost::regex_match(line, matches, pat))
  582. std::cout &lt;&lt; matches[2];
  583. }
  584. }
  585. </pre>
  586. <p>There are two main challenges associated with linking:</p>
  587. <ol class="arabic simple">
  588. <li>Tool configuration, e.g. choosing command-line options or IDE
  589. build settings.</li>
  590. <li>Identifying the library binary, among all the build variants,
  591. whose compile configuration is compatible with the rest of your
  592. project.</li>
  593. </ol>
  594. <div class="section">
  595. <h2><a class="toc-backref" href="#id39" id="microsoft-windows" name="microsoft-windows">5.1&nbsp;&nbsp;&nbsp;Microsoft Windows</a></h2>
  596. <p>Most Windows compilers and linkers have so called “auto-linking
  597. support,” which is used by many Boost libraries to eliminate the
  598. second challenge. Special code in Boost header files detects your
  599. compiler options and uses that information to encode the name of
  600. the correct library into your object files; the linker selects the
  601. library with that name from the directories you've told it to
  602. search.</p>
  603. <div class="note">
  604. <p class="first admonition-title">Note</p>
  605. <p>As of this writing, a few Boost libraries don't support
  606. auto-linking:</p>
  607. <ul class="last simple">
  608. <li>Boost.Python</li>
  609. <li>…others?…</li>
  610. </ul>
  611. </div>
  612. <div class="section">
  613. <h3><a class="toc-backref" href="#id40" id="visual-c-command-line" name="visual-c-command-line">5.1.1&nbsp;&nbsp;&nbsp;Visual C++ Command Line</a></h3>
  614. <p>For example, we can compile and link the above program from the
  615. Visual C++ command-line by simply adding the <strong>bold</strong> text below to
  616. the command line we used earlier, assuming your Boost binaries are
  617. 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_34_0</span></tt><tt class="docutils literal"><span class="pre">\lib</span></tt>:</p>
  618. <pre class="literal-block">
  619. C:PROMPT&gt; cl /EHsc /I <em>C:</em><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 <strong>\</strong>
  620. <strong>/link /LIBPATH:</strong> <strong>C:\Program Files\boost\</strong><strong>boost_1_34_0</strong><strong>\lib</strong>
  621. </pre>
  622. <p>To link with a library that doesn't use auto-linking support, you
  623. need to specify the library name. For example,</p>
  624. <pre class="literal-block">
  625. C:PROMPT&gt; cl /EHsc /I <em>C:</em><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 <strong>\</strong>
  626. /link /LIBPATH: <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_34_0</span></tt> <strong>\</strong>
  627. <strong>boost_regex-msvc-7.1-mt-d-1_34.lib</strong>
  628. </pre>
  629. <p>See <a class="reference" href="#library-naming">Library Naming</a> for details about how to select the right
  630. library name.</p>
  631. </div>
  632. <div class="section">
  633. <h3><a class="toc-backref" href="#id41" id="visual-studio-ide" name="visual-studio-ide">5.1.2&nbsp;&nbsp;&nbsp;Visual Studio IDE</a></h3>
  634. <p>Starting with the <a class="reference" href="#vs-header-only">header-only example project</a> we created
  635. earlier:</p>
  636. <ol class="arabic simple">
  637. <li>Right-click <strong>example</strong> in the <em>Solution Explorer</em> pane and
  638. select <em>Properties</em> from the resulting pop-up menu</li>
  639. <li>In <em>Configuration Properties</em> &gt; <em>Linker</em> &gt; <em>Additional Library
  640. Directories</em>, enter the path to the Boost binaries,
  641. 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_34_0</span></tt><tt class="docutils literal"><span class="pre">\lib\</span></tt>.</li>
  642. <li>From the <em>Build</em> menu, select <em>Build Solution</em>.</li>
  643. </ol>
  644. <p>To link with a library that doesn't use auto-linking support,
  645. before building (step 3 above), you also need to specify the library
  646. name:</p>
  647. <ul class="simple">
  648. <li>In <em>Configuration Properties</em> &gt; <em>Linker</em> &gt; <em>Input</em> &gt;
  649. <em>Additional Dependencies</em>, enter the name of the binary library
  650. to link with, e.g. <strong>boost_regex-msvc-7.1-mt-d-1_34.lib</strong>.</li>
  651. </ul>
  652. <p>See <a class="reference" href="#library-naming">Library Naming</a> for details about how to select the right
  653. library name.</p>
  654. </div>
  655. </div>
  656. <div class="section">
  657. <h2><a class="toc-backref" href="#id42" id="id13" name="id13">5.2&nbsp;&nbsp;&nbsp;*nix (e.g. Unix, Linux, MacOS, Cygwin)</a></h2>
  658. <p>There are two main ways to link to libraries:</p>
  659. <ol class="loweralpha">
  660. <li><p class="first">You can specify the full path to each library:</p>
  661. <pre class="literal-block">
  662. $ 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>
  663. <strong>~/boost/lib/libboost_regex-msvc-7.1-mt-d-1_34.a</strong>
  664. </pre>
  665. </li>
  666. <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="id14" name="id14"><sup>4</sup></a> dropping the filename's leading <tt class="docutils literal"><span class="pre">lib</span></tt> and trailing
  667. suffix (<tt class="docutils literal"><span class="pre">.a</span></tt> in this case):</p>
  668. <pre class="literal-block">
  669. $ 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>
  670. <strong>-L~/boost/lib/ -lboost_regex-msvc-7.1-mt-d-1_34</strong>
  671. </pre>
  672. <p>As you can see, this method is just as terse as method a. for
  673. one library; it <em>really</em> pays off when you're using multiple
  674. libraries from the same directory.</p>
  675. </li>
  676. </ol>
  677. <p>In both cases above, the bold text is what you'd add to <a class="reference" href="#unix-header-only">the
  678. command lines we explored earlier</a>.</p>
  679. </div>
  680. <div class="section">
  681. <h2><a class="toc-backref" href="#id43" id="library-naming" name="library-naming">5.3&nbsp;&nbsp;&nbsp;Library Naming</a></h2>
  682. <p>In order to choose the right library binary to link with, you'll
  683. need to know something about how Boost libraries are named. Each
  684. library binary filename is composed of a common sequence of
  685. elements that describe how it was built. For example,
  686. <tt class="docutils literal"><span class="pre">libboost_regex-msvc-7.1-mt-d-1_34.lib</span></tt> can be broken down into the
  687. following elements:</p>
  688. <dl class="docutils">
  689. <dt><tt class="docutils literal"><span class="pre">lib</span></tt></dt>
  690. <dd><em>Prefix</em>: except on Microsoft Windows, every Boost library
  691. name begins with this string. On Windows, only ordinary static
  692. libraries use the <tt class="docutils literal"><span class="pre">lib</span></tt> prefix; import libraries and DLLs do
  693. not.<a class="footnote-reference" href="#distinct" id="id16" name="id16"><sup>5</sup></a></dd>
  694. <dt><tt class="docutils literal"><span class="pre">boost_regex</span></tt></dt>
  695. <dd><em>Library name</em>: all boost library filenames begin with <tt class="docutils literal"><span class="pre">boost_</span></tt>.</dd>
  696. <dt><tt class="docutils literal"><span class="pre">-msvc-7.1</span></tt></dt>
  697. <dd><em>Toolset tag</em>: one of the <a class="reference" href="#toolset-name">Boost.Build toolset names</a>,
  698. possibly followed by a dash and a version number.</dd>
  699. <dt><tt class="docutils literal"><span class="pre">-mt</span></tt></dt>
  700. <dd><em>Threading tag</em>: indicates that the library was
  701. built with multithreading support enabled. Libraries built
  702. without multithreading support can be identified by the absence
  703. of <tt class="docutils literal"><span class="pre">-mt</span></tt>.</dd>
  704. <dt><tt class="docutils literal"><span class="pre">-d</span></tt></dt>
  705. <dd><p class="first"><em>ABI tag</em>: encodes details that affect the library's
  706. interoperability with other compiled code. For each such
  707. feature, a single letter is added to the tag:</p>
  708. <table border="1" class="docutils">
  709. <colgroup>
  710. <col width="6%" />
  711. <col width="94%" />
  712. </colgroup>
  713. <thead valign="bottom">
  714. <tr><th class="head">Key</th>
  715. <th class="head">Use this library when:</th>
  716. </tr>
  717. </thead>
  718. <tbody valign="top">
  719. <tr><td><tt class="docutils literal"><span class="pre">s</span></tt></td>
  720. <td>linking statically to the C++ standard library and compiler runtime support
  721. libraries.</td>
  722. </tr>
  723. <tr><td><tt class="docutils literal"><span class="pre">g</span></tt></td>
  724. <td>using debug versions of the standard and runtime support libraries.</td>
  725. </tr>
  726. <tr><td><tt class="docutils literal"><span class="pre">y</span></tt></td>
  727. <td>using a special <a class="reference" href="../libs/python/doc/building.html#variants">debug build of Python</a>.</td>
  728. </tr>
  729. <tr><td><tt class="docutils literal"><span class="pre">d</span></tt></td>
  730. <td>building a debug version of your code.<a class="footnote-reference" href="#debug-abi" id="id17" name="id17"><sup>6</sup></a></td>
  731. </tr>
  732. <tr><td><tt class="docutils literal"><span class="pre">p</span></tt></td>
  733. <td>using the STLPort standard library rather than the default one supplied with
  734. your compiler.</td>
  735. </tr>
  736. <tr><td><tt class="docutils literal"><span class="pre">n</span></tt></td>
  737. <td>using STLPort's deprecated “native iostreams” feature.<a class="footnote-reference" href="#native" id="id18" name="id18"><sup>7</sup></a></td>
  738. </tr>
  739. </tbody>
  740. </table>
  741. <p class="last">For example, if you build a debug version of your code for use
  742. with debug versions of the static runtime library and the
  743. STLPort standard library in “native iostreams” mode,
  744. the tag would be: <tt class="docutils literal"><span class="pre">-sgdpn</span></tt>. If none of the above apply, the
  745. ABI tag is ommitted.</p>
  746. </dd>
  747. <dt><tt class="docutils literal"><span class="pre">-1_34</span></tt></dt>
  748. <dd><em>Version tag</em>: the full Boost release number,
  749. with periods replaced by underscores. The major and minor version
  750. numbers are taken together separated by an underscore. For
  751. example, version 1.31.1 would be tagged as &quot;-1_31_1&quot;.</dd>
  752. <dt><tt class="docutils literal"><span class="pre">.lib</span></tt></dt>
  753. <dd><em>Extension</em>: determined according to the
  754. operating system's usual convention. On Windows, <tt class="docutils literal"><span class="pre">.dll</span></tt>
  755. indicates a shared library and <tt class="docutils literal"><span class="pre">.lib</span></tt> indicates a static or
  756. import library. On most *nix platforms the extensions are
  757. <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
  758. libraries, respectively. Where supported by *nix toolsets, a
  759. full version extension is added (e.g. &quot;.so.1.34&quot;); a symbolic
  760. link to the library file, named without the trailing version
  761. number, will also be created.</dd>
  762. </dl>
  763. <hr class="docutils" />
  764. <table class="docutils footnote" frame="void" id="packagers" rules="none">
  765. <colgroup><col class="label" /><col /></colgroup>
  766. <tbody valign="top">
  767. <tr><td class="label"><a class="fn-backref" href="#id3" name="packagers">[1]</a></td><td>If developers of Boost packages would like to work
  768. with us to make sure these instructions can be used with their
  769. packages, we'd be glad to help. Please make your interest known
  770. to the <a class="reference" href="mailing_lists.htm#main">Boost developers' list</a>.</td></tr>
  771. </tbody>
  772. </table>
  773. <table class="docutils footnote" frame="void" id="installer-src" rules="none">
  774. <colgroup><col class="label" /><col /></colgroup>
  775. <tbody valign="top">
  776. <tr><td class="label"><a class="fn-backref" href="#id4" name="installer-src">[2]</a></td><td>If you used the <a class="reference" href="http://www.boost-consulting.com/download.html">Windows installer</a> from Boost
  777. Consulting and deselected “Source and Documentation” (it's
  778. selected by default), you won't see the <tt class="docutils literal"><span class="pre">libs/</span></tt> subdirectory.
  779. That won't affect your ability to use precompiled binaries, but
  780. you won't be able to rebuild libraries from scratch.</td></tr>
  781. </tbody>
  782. </table>
  783. <table class="docutils footnote" frame="void" id="pch" rules="none">
  784. <colgroup><col class="label" /><col /></colgroup>
  785. <tbody valign="top">
  786. <tr><td class="label"><a class="fn-backref" href="#id6" name="pch">[3]</a></td><td>There's no problem using Boost with precompiled headers;
  787. these instructions merely avoid precompiled headers because it
  788. would require Visual Studio-specific changes to the source code
  789. used in the examples.</td></tr>
  790. </tbody>
  791. </table>
  792. <table class="docutils footnote" frame="void" id="lowercase-l" rules="none">
  793. <colgroup><col class="label" /><col /></colgroup>
  794. <tbody valign="top">
  795. <tr><td class="label"><a class="fn-backref" href="#id14" name="lowercase-l">[4]</a></td><td>That option is a dash followed by a lowercase “L”
  796. character, which looks very much like a numeral 1 in some fonts.</td></tr>
  797. </tbody>
  798. </table>
  799. <table class="docutils footnote" frame="void" id="distinct" rules="none">
  800. <colgroup><col class="label" /><col /></colgroup>
  801. <tbody valign="top">
  802. <tr><td class="label"><a class="fn-backref" href="#id16" name="distinct">[5]</a></td><td>This convention distinguishes the static version of
  803. a Boost library from the import library for an
  804. identically-configured Boost DLL, which would otherwise have the
  805. same name.</td></tr>
  806. </tbody>
  807. </table>
  808. <table class="docutils footnote" frame="void" id="debug-abi" rules="none">
  809. <colgroup><col class="label" /><col /></colgroup>
  810. <tbody valign="top">
  811. <tr><td class="label"><a class="fn-backref" href="#id17" name="debug-abi">[6]</a></td><td>These libraries were compiled without optimization
  812. or inlining, with full debug symbols enabled, and without
  813. <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
  814. these choices don't affect binary compatibility with other
  815. compiled code, you can't count on that with Boost libraries.</td></tr>
  816. </tbody>
  817. </table>
  818. <table class="docutils footnote" frame="void" id="native" rules="none">
  819. <colgroup><col class="label" /><col /></colgroup>
  820. <tbody valign="top">
  821. <tr><td class="label"><a class="fn-backref" href="#id18" name="native">[7]</a></td><td>This feature of STLPort is deprecated because it's
  822. impossible to make it work transparently to the user; we don't
  823. recommend it.</td></tr>
  824. </tbody>
  825. </table>
  826. </div>
  827. </div>
  828. </div>
  829. <div class="footer">
  830. <hr class="footer" />
  831. <a class="reference" href="./getting_started.rst">View document source</a>.
  832. Generated on: 2006-11-20 13:06 UTC.
  833. 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.
  834. </div>
  835. </body>
  836. </html>
粤ICP备19079148号