| 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 on Unix Variants</title> |
|---|
| 8 | <meta content="Getting Started with Boost on Unix Variants (including Linux and MacOS)" name="description" /> |
|---|
| 9 | <link rel="stylesheet" href="../../rst.css" type="text/css" /> |
|---|
| 10 | </head> |
|---|
| 11 | <body> |
|---|
| 12 | <div class="document" id="logo-getting-started-on-unix-variants"> |
|---|
| 13 | <h1 class="title"><a class="reference external" href="../../index.htm"><img alt="Boost" class="boost-logo" src="../../boost.png" /></a> Getting Started on Unix Variants</h1> |
|---|
| 14 | |
|---|
| 15 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 16 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 17 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 18 | <!-- maybe we don't need this |
|---|
| 19 | .. Admonition:: A note to Cygwin_ and MinGW_ users |
|---|
| 20 | |
|---|
| 21 | If you plan to build from the Cygwin_ bash shell, you're in the |
|---|
| 22 | right place. If you plan to use your tools from the Windows |
|---|
| 23 | command prompt, you should follow the instructions for `getting |
|---|
| 24 | started on Windows`_. Other command shells, such as MinGW_\ 's |
|---|
| 25 | MSYS, are not supported—they may or may not work. |
|---|
| 26 | |
|---|
| 27 | .. _`Getting Started on Windows`: windows.html |
|---|
| 28 | .. _Cygwin: http://www.cygwin.com |
|---|
| 29 | .. _MinGW: http://mingw.org --> |
|---|
| 30 | <div class="contents topic" id="index"> |
|---|
| 31 | <p class="topic-title first">Index</p> |
|---|
| 32 | <ul class="auto-toc simple"> |
|---|
| 33 | <li><a class="reference internal" href="#get-boost" id="id18">1 Get Boost</a></li> |
|---|
| 34 | <li><a class="reference internal" href="#the-boost-distribution" id="id19">2 The Boost Distribution</a></li> |
|---|
| 35 | <li><a class="reference internal" href="#header-only-libraries" id="id20">3 Header-Only Libraries</a></li> |
|---|
| 36 | <li><a class="reference internal" href="#build-a-simple-program-using-boost" id="id21">4 Build a Simple Program Using Boost</a><ul class="auto-toc"> |
|---|
| 37 | <li><a class="reference internal" href="#errors-and-warnings" id="id22">4.1 Errors and Warnings</a></li> |
|---|
| 38 | </ul> |
|---|
| 39 | </li> |
|---|
| 40 | <li><a class="reference internal" href="#prepare-to-use-a-boost-library-binary" id="id23">5 Prepare to Use a Boost Library Binary</a><ul class="auto-toc"> |
|---|
| 41 | <li><a class="reference internal" href="#easy-build-and-install" id="id24">5.1 Easy Build and Install</a></li> |
|---|
| 42 | <li><a class="reference internal" href="#or-build-custom-binaries" id="id25">5.2 Or, Build Custom Binaries</a><ul class="auto-toc"> |
|---|
| 43 | <li><a class="reference internal" href="#get-bjam" id="id26">5.2.1 Get <tt class="docutils literal"><span class="pre">bjam</span></tt></a></li> |
|---|
| 44 | <li><a class="reference internal" href="#identify-your-toolset" id="id27">5.2.2 Identify Your Toolset</a></li> |
|---|
| 45 | <li><a class="reference internal" href="#select-a-build-directory" id="id28">5.2.3 Select a Build Directory</a></li> |
|---|
| 46 | <li><a class="reference internal" href="#invoke-bjam" id="id29">5.2.4 Invoke <tt class="docutils literal"><span class="pre">bjam</span></tt></a></li> |
|---|
| 47 | </ul> |
|---|
| 48 | </li> |
|---|
| 49 | <li><a class="reference internal" href="#expected-build-output" id="id30">5.3 Expected Build Output</a></li> |
|---|
| 50 | <li><a class="reference internal" href="#in-case-of-build-errors" id="id31">5.4 In Case of Build Errors</a></li> |
|---|
| 51 | </ul> |
|---|
| 52 | </li> |
|---|
| 53 | <li><a class="reference internal" href="#link-your-program-to-a-boost-library" id="id32">6 Link Your Program to a Boost Library</a><ul class="auto-toc"> |
|---|
| 54 | <li><a class="reference internal" href="#library-naming" id="id33">6.1 Library Naming</a></li> |
|---|
| 55 | <li><a class="reference internal" href="#test-your-program" id="id34">6.2 Test Your Program</a></li> |
|---|
| 56 | </ul> |
|---|
| 57 | </li> |
|---|
| 58 | <li><a class="reference internal" href="#conclusion-and-further-resources" id="id35">7 Conclusion and Further Resources</a></li> |
|---|
| 59 | </ul> |
|---|
| 60 | </div> |
|---|
| 61 | <div class="section" id="get-boost"> |
|---|
| 62 | <h1><a class="toc-backref" href="#id18">1 Get Boost</a></h1> |
|---|
| 63 | <p>The most reliable way to get a copy of Boost is to download a |
|---|
| 64 | distribution from <a class="reference external" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041">SourceForge</a>:</p> |
|---|
| 65 | <ol class="arabic"> |
|---|
| 66 | <li><p class="first">Download <a class="reference external" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041"><tt class="docutils literal"><span class="pre">boost_1_34_1</span></tt><tt class="docutils literal"><span class="pre">.tar.bz2</span></tt></a>.</p> |
|---|
| 67 | </li> |
|---|
| 68 | <li><p class="first">In the directory where you want to put the Boost installation, |
|---|
| 69 | execute</p> |
|---|
| 70 | <pre class="literal-block"> |
|---|
| 71 | tar --bzip2 -xf <em>/path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_1</span></tt>.tar.bz2 |
|---|
| 72 | </pre> |
|---|
| 73 | </li> |
|---|
| 74 | </ol> |
|---|
| 75 | <div class="admonition-other-packages admonition"> |
|---|
| 76 | <p class="first admonition-title">Other Packages</p> |
|---|
| 77 | <p class="last">RedHat, Debian, and other distribution packagers supply Boost |
|---|
| 78 | library packages, however you may need to adapt these |
|---|
| 79 | instructions if you use third-party packages, because their |
|---|
| 80 | creators usually choose to break Boost up into several packages, |
|---|
| 81 | reorganize the directory structure of the Boost distribution, |
|---|
| 82 | and/or rename the library binaries.<a class="footnote-reference" href="#packagers" id="id2"><sup>1</sup></a> If you have |
|---|
| 83 | any trouble, we suggest using an official Boost distribution |
|---|
| 84 | from <a class="reference external" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=8041">SourceForge</a>.</p> |
|---|
| 85 | </div> |
|---|
| 86 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 87 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 88 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 89 | </div> |
|---|
| 90 | <div class="section" id="the-boost-distribution"> |
|---|
| 91 | <h1><a class="toc-backref" href="#id19">2 The Boost Distribution</a></h1> |
|---|
| 92 | <p>This is a sketch of the resulting directory structure:</p> |
|---|
| 93 | <pre class="literal-block"> |
|---|
| 94 | <strong>boost_1_34_1</strong><strong>/</strong> .................<em>The “boost root directory”</em> |
|---|
| 95 | <strong>index.htm</strong> .........<em>A copy of www.boost.org starts here</em> |
|---|
| 96 | <strong>boost</strong><strong>/</strong> .........................<em>All Boost Header files</em> |
|---|
| 97 | <tt class="docutils literal"> </tt> |
|---|
| 98 | <strong>libs</strong><strong>/</strong> ............<em>Tests, .cpp</em>s<em>, docs, etc., by library</em> |
|---|
| 99 | <strong>index.html</strong> ........<em>Library documentation starts here</em> |
|---|
| 100 | <strong>algorithm</strong><strong>/</strong> |
|---|
| 101 | <strong>any</strong><strong>/</strong> |
|---|
| 102 | <strong>array</strong><strong>/</strong> |
|---|
| 103 | <em>…more libraries…</em> |
|---|
| 104 | <strong>status</strong><strong>/</strong> .........................<em>Boost-wide test suite</em> |
|---|
| 105 | <strong>tools</strong><strong>/</strong> ...........<em>Utilities, e.g. bjam, quickbook, bcp</em> |
|---|
| 106 | <strong>more</strong><strong>/</strong> ..........................<em>Policy documents, etc.</em> |
|---|
| 107 | <strong>doc</strong><strong>/</strong> ...............<em>A subset of all Boost library docs</em> |
|---|
| 108 | </pre> |
|---|
| 109 | <div class="sidebar"> |
|---|
| 110 | <p class="first sidebar-title">Header Organization</p> |
|---|
| 111 | <p class="pre-wrap">The organization of Boost library headers isn't entirely uniform, |
|---|
| 112 | but most libraries follow a few patterns:</p> |
|---|
| 113 | <ul class="pre-wrap last"> |
|---|
| 114 | <li><p class="first">Some older libraries and most very small libraries place all |
|---|
| 115 | public headers directly into <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt>.</p> |
|---|
| 116 | </li> |
|---|
| 117 | <li><p class="first">Most libraries' public headers live in a subdirectory of |
|---|
| 118 | <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt>, named after the library. For example, you'll find |
|---|
| 119 | the Python library's <tt class="docutils literal"><span class="pre">def.hpp</span></tt> header in</p> |
|---|
| 120 | <pre class="literal-block"> |
|---|
| 121 | <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt><tt class="docutils literal"><span class="pre">python</span></tt><tt class="docutils literal"><span class="pre">/</span></tt><tt class="docutils literal"><span class="pre">def.hpp</span></tt>. |
|---|
| 122 | </pre> |
|---|
| 123 | </li> |
|---|
| 124 | <li><p class="first">Some libraries have an “aggregate header” in <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt> that |
|---|
| 125 | <tt class="docutils literal"><span class="pre">#include</span></tt>s all of the library's other headers. For |
|---|
| 126 | example, <a class="reference external" href="../../libs/python/doc/building.html">Boost.Python</a>'s aggregate header is</p> |
|---|
| 127 | <pre class="literal-block"> |
|---|
| 128 | <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt><tt class="docutils literal"><span class="pre">python.hpp</span></tt>. |
|---|
| 129 | </pre> |
|---|
| 130 | </li> |
|---|
| 131 | <li><p class="first">Most libraries place private headers in a subdirectory called |
|---|
| 132 | <tt class="docutils literal"><span class="pre">detail</span></tt><tt class="docutils literal"><span class="pre">/</span></tt>, or <tt class="docutils literal"><span class="pre">aux_</span></tt><tt class="docutils literal"><span class="pre">/</span></tt>. Don't expect to find |
|---|
| 133 | anything you can use in these directories.</p> |
|---|
| 134 | </li> |
|---|
| 135 | </ul> |
|---|
| 136 | </div> |
|---|
| 137 | <p>It's important to note the following:</p> |
|---|
| 138 | <ol class="arabic" id="boost-root-directory"> |
|---|
| 139 | <li><p class="first">The path to the <strong>boost root directory</strong> (often <tt class="docutils literal"><span class="pre">/usr/local/</span></tt><tt class="docutils literal"><span class="pre">boost_1_34_1</span></tt>) is |
|---|
| 140 | sometimes referred to as <tt class="docutils literal"><span class="pre">$BOOST_ROOT</span></tt> in documentation and |
|---|
| 141 | mailing lists .</p> |
|---|
| 142 | </li> |
|---|
| 143 | <li><p class="first">To compile anything in Boost, you need a directory containing |
|---|
| 144 | the <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt> subdirectory in your <tt class="docutils literal"><span class="pre">#include</span></tt> path. <tt class="docutils literal"> </tt></p> |
|---|
| 145 | </li> |
|---|
| 146 | <li><p class="first">Since all of Boost's header files have the <tt class="docutils literal"><span class="pre">.hpp</span></tt> extension, |
|---|
| 147 | and live in the <tt class="docutils literal"><span class="pre">boost</span></tt><tt class="docutils literal"><span class="pre">/</span></tt> subdirectory of the boost root, your |
|---|
| 148 | Boost <tt class="docutils literal"><span class="pre">#include</span></tt> directives will look like:</p> |
|---|
| 149 | <pre class="literal-block"> |
|---|
| 150 | #include <boost/<em>whatever</em>.hpp> |
|---|
| 151 | </pre> |
|---|
| 152 | <p>or</p> |
|---|
| 153 | <pre class="literal-block"> |
|---|
| 154 | #include "boost/<em>whatever</em>.hpp" |
|---|
| 155 | </pre> |
|---|
| 156 | <p>depending on your preference regarding the use of angle bracket |
|---|
| 157 | includes. <tt class="docutils literal"> </tt></p> |
|---|
| 158 | </li> |
|---|
| 159 | <li><p class="first">Don't be distracted by the <tt class="docutils literal"><span class="pre">doc</span></tt><tt class="docutils literal"><span class="pre">/</span></tt> subdirectory; it only |
|---|
| 160 | contains a subset of the Boost documentation. Start with |
|---|
| 161 | <tt class="docutils literal"><span class="pre">libs</span></tt><tt class="docutils literal"><span class="pre">/</span></tt><tt class="docutils literal"><span class="pre">index.html</span></tt> if you're looking for the whole enchilada.</p> |
|---|
| 162 | </li> |
|---|
| 163 | </ol> |
|---|
| 164 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 165 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 166 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 167 | </div> |
|---|
| 168 | <div class="section" id="header-only-libraries"> |
|---|
| 169 | <h1><a class="toc-backref" href="#id20">3 Header-Only Libraries</a></h1> |
|---|
| 170 | <p>The first thing many people want to know is, “how do I build |
|---|
| 171 | Boost?” The good news is that often, there's nothing to build.</p> |
|---|
| 172 | <div class="admonition-nothing-to-build admonition"> |
|---|
| 173 | <p class="first admonition-title">Nothing to Build?</p> |
|---|
| 174 | <p class="last">Most Boost libraries are <strong>header-only</strong>: they consist <em>entirely |
|---|
| 175 | of header files</em> containing templates and inline functions, and |
|---|
| 176 | require no separately-compiled library binaries or special |
|---|
| 177 | treatment when linking.</p> |
|---|
| 178 | </div> |
|---|
| 179 | <!-- .. _separate: --> |
|---|
| 180 | <p>The only Boost libraries that <em>must</em> be built separately are:</p> |
|---|
| 181 | <ul class="simple"> |
|---|
| 182 | <li><a class="reference external" href="../../libs/filesystem/index.html">Boost.Filesystem</a></li> |
|---|
| 183 | <li><a class="reference external" href="../../libs/iostreams/index.html">Boost.IOStreams</a></li> |
|---|
| 184 | <li><a class="reference external" href="../../libs/program_options/index.html">Boost.ProgramOptions</a></li> |
|---|
| 185 | <li><a class="reference external" href="../../libs/python/doc/building.html">Boost.Python</a> (see the <a class="reference external" href="../../libs/python/doc/building.html">Boost.Python build documentation</a> |
|---|
| 186 | before building and installing it)</li> |
|---|
| 187 | <li><a class="reference external" href="../../libs/regex/index.html">Boost.Regex</a></li> |
|---|
| 188 | <li><a class="reference external" href="../../libs/serialization/index.html">Boost.Serialization</a></li> |
|---|
| 189 | <li><a class="reference external" href="../../libs/signals/index.html">Boost.Signals</a></li> |
|---|
| 190 | <li><a class="reference external" href="../../doc/html/thread/build.html#thread.build">Boost.Thread</a></li> |
|---|
| 191 | <li><a class="reference external" href="../../libs/wave/index.html">Boost.Wave</a></li> |
|---|
| 192 | </ul> |
|---|
| 193 | <p>A few libraries have optional separately-compiled binaries:</p> |
|---|
| 194 | <ul class="simple"> |
|---|
| 195 | <li><a class="reference external" href="../../libs/date_time/index.html">Boost.DateTime</a> has a binary component that is only needed if |
|---|
| 196 | you're using its <tt class="docutils literal"><span class="pre">to_string</span></tt>/<tt class="docutils literal"><span class="pre">from_string</span></tt> or serialization |
|---|
| 197 | features, or if you're targeting Visual C++ 6.x or Borland.</li> |
|---|
| 198 | <li><a class="reference external" href="../../libs/graph/index.html">Boost.Graph</a> also has a binary component that is only needed if |
|---|
| 199 | you intend to <a class="reference external" href="../../libs/graph/doc/read_graphviz.html">parse GraphViz files</a>.</li> |
|---|
| 200 | <li><a class="reference external" href="../../libs/test/index.html">Boost.Test</a> can be used in “header-only” or “separately compiled” |
|---|
| 201 | mode, although <strong>separate compilation is recommended for serious |
|---|
| 202 | use</strong>.</li> |
|---|
| 203 | </ul> |
|---|
| 204 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 205 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 206 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 207 | </div> |
|---|
| 208 | <div class="section" id="build-a-simple-program-using-boost"> |
|---|
| 209 | <h1><a class="toc-backref" href="#id21">4 Build a Simple Program Using Boost</a></h1> |
|---|
| 210 | <p>To keep things simple, let's start by using a header-only library. |
|---|
| 211 | The following program reads a sequence of integers from standard |
|---|
| 212 | input, uses Boost.Lambda to multiply each number by three, and |
|---|
| 213 | writes them to standard output:</p> |
|---|
| 214 | <pre class="literal-block"> |
|---|
| 215 | #include <boost/lambda/lambda.hpp> |
|---|
| 216 | #include <iostream> |
|---|
| 217 | #include <iterator> |
|---|
| 218 | #include <algorithm> |
|---|
| 219 | |
|---|
| 220 | int main() |
|---|
| 221 | { |
|---|
| 222 | using namespace boost::lambda; |
|---|
| 223 | typedef std::istream_iterator<int> in; |
|---|
| 224 | |
|---|
| 225 | std::for_each( |
|---|
| 226 | in(std::cin), in(), std::cout << (_1 * 3) << " " ); |
|---|
| 227 | } |
|---|
| 228 | </pre> |
|---|
| 229 | <p>Copy the text of this program into a file called <tt class="docutils literal"><span class="pre">example.cpp</span></tt>.</p> |
|---|
| 230 | <p>Now, in the directory where you saved <tt class="docutils literal"><span class="pre">example.cpp</span></tt>, issue the |
|---|
| 231 | following command:</p> |
|---|
| 232 | <pre class="literal-block"> |
|---|
| 233 | c++ -I <em>path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_1</span></tt> example.cpp -o example |
|---|
| 234 | </pre> |
|---|
| 235 | <p>To test the result, type:</p> |
|---|
| 236 | <pre class="literal-block"> |
|---|
| 237 | echo 1 2 3 | ./example |
|---|
| 238 | </pre> |
|---|
| 239 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 240 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 241 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 242 | <div class="section" id="errors-and-warnings"> |
|---|
| 243 | <h2><a class="toc-backref" href="#id22">4.1 Errors and Warnings</a></h2> |
|---|
| 244 | <p>Don't be alarmed if you see compiler warnings originating in Boost |
|---|
| 245 | headers. We try to eliminate them, but doing so isn't always |
|---|
| 246 | practical.<a class="footnote-reference" href="#warnings" id="id5"><sup>3</sup></a> <strong>Errors are another matter</strong>. If you're |
|---|
| 247 | seeing compilation errors at this point in the tutorial, check to |
|---|
| 248 | be sure you've copied the <a class="reference internal" href="#build-a-simple-program-using-boost">example program</a> correctly and that you've |
|---|
| 249 | correctly identified the <a class="reference internal" href="#boost-root-directory">Boost root directory</a>.</p> |
|---|
| 250 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 251 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 252 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 253 | </div> |
|---|
| 254 | </div> |
|---|
| 255 | <div class="section" id="prepare-to-use-a-boost-library-binary"> |
|---|
| 256 | <h1><a class="toc-backref" href="#id23">5 Prepare to Use a Boost Library Binary</a></h1> |
|---|
| 257 | <p>If you want to use any of the separately-compiled Boost libraries, |
|---|
| 258 | you'll need to acquire library binaries.</p> |
|---|
| 259 | <div class="section" id="easy-build-and-install"> |
|---|
| 260 | <h2><a class="toc-backref" href="#id24">5.1 Easy Build and Install</a></h2> |
|---|
| 261 | <p>Issue the following commands in the shell (don't type <tt class="docutils literal"><span class="pre">$</span></tt>; that |
|---|
| 262 | represents the shell's prompt):</p> |
|---|
| 263 | <pre class="literal-block"> |
|---|
| 264 | <strong>$</strong> cd <em>path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_1</span></tt> |
|---|
| 265 | <strong>$</strong> ./configure --help |
|---|
| 266 | </pre> |
|---|
| 267 | <p>Select your configuration options and invoke <tt class="docutils literal"><span class="pre">./configure</span></tt> again |
|---|
| 268 | without the <tt class="docutils literal"><span class="pre">--help</span></tt> option. Unless you have write permission in |
|---|
| 269 | your system's <tt class="docutils literal"><span class="pre">/usr/local/</span></tt> directory, you'll probably want to at |
|---|
| 270 | least use</p> |
|---|
| 271 | <pre class="literal-block"> |
|---|
| 272 | <strong>$</strong> ./configure <strong>--prefix=</strong><em>path</em>/<em>to</em>/<em>installation</em>/<em>prefix</em> |
|---|
| 273 | </pre> |
|---|
| 274 | <p>to install somewhere else. Also, consider using the |
|---|
| 275 | <tt class="docutils literal"><span class="pre">--show-libraries</span></tt> and <tt class="docutils literal"><span class="pre">--with-libraries=</span></tt> options to limit the |
|---|
| 276 | long wait you'll experience if you build everything. Finally,</p> |
|---|
| 277 | <pre class="literal-block"> |
|---|
| 278 | <strong>$</strong> make install |
|---|
| 279 | </pre> |
|---|
| 280 | <p>will leave Boost binaries in the <tt class="docutils literal"><span class="pre">lib/</span></tt> subdirectory of your |
|---|
| 281 | installation prefix. You will also find a copy of the Boost |
|---|
| 282 | headers in the <tt class="docutils literal"><span class="pre">include/</span></tt> subdirectory of the installation |
|---|
| 283 | prefix, so you can henceforth use that directory as an <tt class="docutils literal"><span class="pre">#include</span></tt> |
|---|
| 284 | path in place of the Boost root directory.</p> |
|---|
| 285 | <p><a class="reference internal" href="#link-your-program-to-a-boost-library"><em>skip to the next step</em></a></p> |
|---|
| 286 | </div> |
|---|
| 287 | <div class="section" id="or-build-custom-binaries"> |
|---|
| 288 | <h2><a class="toc-backref" href="#id25">5.2 Or, Build Custom Binaries</a></h2> |
|---|
| 289 | <p>If you're using a compiler other than your system's default, you'll |
|---|
| 290 | need to use <a class="reference external" href="../../tools/build/index.html">Boost.Build</a> to create binaries. You'll also |
|---|
| 291 | use this method if you need a nonstandard build variant (see the |
|---|
| 292 | <a class="reference external" href="../../tools/build/index.html">Boost.Build documentation</a> for more details).</p> |
|---|
| 293 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 294 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 295 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 296 | <p><a class="reference external" href="../../tools/build/index.html">Boost.Build</a> is a text-based system for developing, testing, and |
|---|
| 297 | installing software. To use it, you'll need an executable called |
|---|
| 298 | <tt class="docutils literal"><span class="pre">bjam</span></tt>.</p> |
|---|
| 299 | <!-- .. _Boost.Jam documentation: Boost.Jam_ --> |
|---|
| 300 | <div class="section" id="get-bjam"> |
|---|
| 301 | <h3><a class="toc-backref" href="#id26">5.2.1 Get <tt class="docutils literal"><span class="pre">bjam</span></tt></a></h3> |
|---|
| 302 | <p><tt class="docutils literal"><span class="pre">bjam</span></tt> is the command-line tool that drives the Boost Build |
|---|
| 303 | system. To build Boost binaries, you'll invoke <tt class="docutils literal"><span class="pre">bjam</span></tt> from the |
|---|
| 304 | Boost root.</p> |
|---|
| 305 | <p>Boost provides <a class="reference external" href="http://sourceforge.net/project/showfiles.php?group_id=7586&package_id=72941">pre-compiled <tt class="docutils literal"><span class="pre">bjam</span></tt> executables</a> for a variety of platforms. |
|---|
| 306 | Alternatively, you can build <tt class="docutils literal"><span class="pre">bjam</span></tt> yourself using <a class="reference external" href="../../doc/html/jam/building.html">these |
|---|
| 307 | instructions</a>.</p> |
|---|
| 308 | </div> |
|---|
| 309 | <div class="section" id="identify-your-toolset"> |
|---|
| 310 | <span id="toolset-name"></span><span id="toolset"></span><h3><a class="toc-backref" href="#id27">5.2.2 Identify Your Toolset</a></h3> |
|---|
| 311 | <p>First, find the toolset corresponding to your compiler in the |
|---|
| 312 | following table.</p> |
|---|
| 313 | <div class="note"> |
|---|
| 314 | <p class="first admonition-title">Note</p> |
|---|
| 315 | <p class="last">If you previously chose a toolset for the purposes of |
|---|
| 316 | <a class="reference external" href="../../doc/html/jam/building.html">building bjam</a>, you should assume it won't work and instead |
|---|
| 317 | choose newly from the table below.</p> |
|---|
| 318 | </div> |
|---|
| 319 | <table border="1" class="docutils"> |
|---|
| 320 | <colgroup> |
|---|
| 321 | <col width="18%" /> |
|---|
| 322 | <col width="33%" /> |
|---|
| 323 | <col width="48%" /> |
|---|
| 324 | </colgroup> |
|---|
| 325 | <thead valign="bottom"> |
|---|
| 326 | <tr><th class="head">Toolset |
|---|
| 327 | Name</th> |
|---|
| 328 | <th class="head">Vendor</th> |
|---|
| 329 | <th class="head">Notes</th> |
|---|
| 330 | </tr> |
|---|
| 331 | </thead> |
|---|
| 332 | <tbody valign="top"> |
|---|
| 333 | <tr><td><tt class="docutils literal"><span class="pre">acc</span></tt></td> |
|---|
| 334 | <td>Hewlett Packard</td> |
|---|
| 335 | <td>Only very recent versions are |
|---|
| 336 | known to work well with Boost</td> |
|---|
| 337 | </tr> |
|---|
| 338 | <tr><td><tt class="docutils literal"><span class="pre">borland</span></tt></td> |
|---|
| 339 | <td>Borland</td> |
|---|
| 340 | <td> </td> |
|---|
| 341 | </tr> |
|---|
| 342 | <tr><td><tt class="docutils literal"><span class="pre">como</span></tt></td> |
|---|
| 343 | <td>Comeau Computing</td> |
|---|
| 344 | <td>Using this toolset may |
|---|
| 345 | require <a class="reference external" href="../../tools/build/index.html">configuring</a> another |
|---|
| 346 | toolset to act as its backend</td> |
|---|
| 347 | </tr> |
|---|
| 348 | <tr><td><tt class="docutils literal"><span class="pre">cw</span></tt></td> |
|---|
| 349 | <td>Metrowerks/FreeScale</td> |
|---|
| 350 | <td>The CodeWarrior compiler. We |
|---|
| 351 | have not tested versions of |
|---|
| 352 | this compiler produced since |
|---|
| 353 | it was sold to FreeScale.</td> |
|---|
| 354 | </tr> |
|---|
| 355 | <tr><td><tt class="docutils literal"><span class="pre">dmc</span></tt></td> |
|---|
| 356 | <td>Digital Mars</td> |
|---|
| 357 | <td>As of this Boost release, no |
|---|
| 358 | version of dmc is known to |
|---|
| 359 | handle Boost well.</td> |
|---|
| 360 | </tr> |
|---|
| 361 | <tr><td><tt class="docutils literal"><span class="pre">darwin</span></tt></td> |
|---|
| 362 | <td>Apple Computer</td> |
|---|
| 363 | <td>Apple's version of the GCC |
|---|
| 364 | toolchain with support for |
|---|
| 365 | Darwin and MacOS X features |
|---|
| 366 | such as frameworks.</td> |
|---|
| 367 | </tr> |
|---|
| 368 | <tr><td><tt class="docutils literal"><span class="pre">gcc</span></tt></td> |
|---|
| 369 | <td>The Gnu Project</td> |
|---|
| 370 | <td>Includes support for Cygwin |
|---|
| 371 | and MinGW compilers.</td> |
|---|
| 372 | </tr> |
|---|
| 373 | <tr><td><tt class="docutils literal"><span class="pre">hp_cxx</span></tt></td> |
|---|
| 374 | <td>Hewlett Packard</td> |
|---|
| 375 | <td>Targeted at the Tru64 |
|---|
| 376 | operating system.</td> |
|---|
| 377 | </tr> |
|---|
| 378 | <tr><td><tt class="docutils literal"><span class="pre">intel</span></tt></td> |
|---|
| 379 | <td>Intel</td> |
|---|
| 380 | <td> </td> |
|---|
| 381 | </tr> |
|---|
| 382 | <tr><td><tt class="docutils literal"><span class="pre">kylix</span></tt></td> |
|---|
| 383 | <td>Borland</td> |
|---|
| 384 | <td> </td> |
|---|
| 385 | </tr> |
|---|
| 386 | <tr><td><tt class="docutils literal"><span class="pre">msvc</span></tt></td> |
|---|
| 387 | <td>Microsoft</td> |
|---|
| 388 | <td> </td> |
|---|
| 389 | </tr> |
|---|
| 390 | <tr><td><tt class="docutils literal"><span class="pre">qcc</span></tt></td> |
|---|
| 391 | <td>QNX Software Systems</td> |
|---|
| 392 | <td> </td> |
|---|
| 393 | </tr> |
|---|
| 394 | <tr><td><tt class="docutils literal"><span class="pre">sun</span></tt></td> |
|---|
| 395 | <td>Sun</td> |
|---|
| 396 | <td>Only very recent versions are |
|---|
| 397 | known to work well with |
|---|
| 398 | Boost.</td> |
|---|
| 399 | </tr> |
|---|
| 400 | <tr><td><tt class="docutils literal"><span class="pre">vacpp</span></tt></td> |
|---|
| 401 | <td>IBM</td> |
|---|
| 402 | <td>The VisualAge C++ compiler.</td> |
|---|
| 403 | </tr> |
|---|
| 404 | </tbody> |
|---|
| 405 | </table> |
|---|
| 406 | <p>If you have multiple versions of a particular compiler installed, |
|---|
| 407 | you can append the version number to the toolset name, preceded by |
|---|
| 408 | a hyphen, e.g. <tt class="docutils literal"><span class="pre">intel-9.0</span></tt> or |
|---|
| 409 | <tt class="docutils literal"><span class="pre">borland-5.4.3</span></tt>. <tt class="docutils literal"> </tt></p> |
|---|
| 410 | </div> |
|---|
| 411 | <div class="section" id="select-a-build-directory"> |
|---|
| 412 | <span id="id10"></span><span id="build-directory"></span><h3><a class="toc-backref" href="#id28">5.2.3 Select a Build Directory</a></h3> |
|---|
| 413 | <p><a class="reference external" href="../../tools/build/index.html">Boost.Build</a> will place all intermediate files it generates while |
|---|
| 414 | building into the <strong>build directory</strong>. If your Boost root |
|---|
| 415 | directory is writable, this step isn't strictly necessary: by |
|---|
| 416 | default Boost.Build will create a <tt class="docutils literal"><span class="pre">bin.v2/</span></tt> subdirectory for that |
|---|
| 417 | purpose in your current working directory.</p> |
|---|
| 418 | </div> |
|---|
| 419 | <div class="section" id="invoke-bjam"> |
|---|
| 420 | <h3><a class="toc-backref" href="#id29">5.2.4 Invoke <tt class="docutils literal"><span class="pre">bjam</span></tt></a></h3> |
|---|
| 421 | <p>Change your current directory to the Boost root directory and |
|---|
| 422 | invoke <tt class="docutils literal"><span class="pre">bjam</span></tt> as follows:</p> |
|---|
| 423 | <pre class="literal-block"> |
|---|
| 424 | bjam <strong>--build-dir=</strong><a class="reference internal" href="#id10"><em>build-directory</em></a> <strong>--toolset=</strong><a class="reference internal" href="#toolset-name"><em>toolset-name</em></a> stage |
|---|
| 425 | </pre> |
|---|
| 426 | <p>For example, your session might look like this:</p> |
|---|
| 427 | <pre class="literal-block"> |
|---|
| 428 | $ cd ~/<tt class="docutils literal"><span class="pre">boost_1_34_1</span></tt> |
|---|
| 429 | $ bjam <strong>--build-dir=</strong>/tmp/build-boost <strong>--toolset=</strong>gcc stage |
|---|
| 430 | </pre> |
|---|
| 431 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 432 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 433 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 434 | <p>Building the special <tt class="docutils literal"><span class="pre">stage</span></tt> target places Boost |
|---|
| 435 | library binaries in the <tt class="docutils literal"><span class="pre">stage</span></tt><tt class="docutils literal"><span class="pre">/</span></tt> subdirectory of your <a class="reference internal" href="#build-directory">build |
|---|
| 436 | directory</a>.</p> |
|---|
| 437 | <div class="note"> |
|---|
| 438 | <p class="first admonition-title">Note</p> |
|---|
| 439 | <p class="last"><tt class="docutils literal"><span class="pre">bjam</span></tt> is case-sensitive; it is important that all the |
|---|
| 440 | parts shown in <strong>bold</strong> type above be entirely lower-case.</p> |
|---|
| 441 | </div> |
|---|
| 442 | <p>For a description of other options you can pass when invoking |
|---|
| 443 | <tt class="docutils literal"><span class="pre">bjam</span></tt>, type:</p> |
|---|
| 444 | <pre class="literal-block"> |
|---|
| 445 | bjam --help |
|---|
| 446 | </pre> |
|---|
| 447 | <p>In particular, to limit the amount of time spent building, you may |
|---|
| 448 | be interested in:</p> |
|---|
| 449 | <ul class="simple"> |
|---|
| 450 | <li>reviewing the list of library names with <tt class="docutils literal"><span class="pre">--show-libraries</span></tt></li> |
|---|
| 451 | <li>limiting which libraries get built with the <tt class="docutils literal"><span class="pre">--with-</span></tt><em>library-name</em> or <tt class="docutils literal"><span class="pre">--without-</span></tt><em>library-name</em> options</li> |
|---|
| 452 | <li>choosing a specific build variant by adding <tt class="docutils literal"><span class="pre">release</span></tt> or |
|---|
| 453 | <tt class="docutils literal"><span class="pre">debug</span></tt> to the command line.</li> |
|---|
| 454 | </ul> |
|---|
| 455 | </div> |
|---|
| 456 | </div> |
|---|
| 457 | <div class="section" id="expected-build-output"> |
|---|
| 458 | <h2><a class="toc-backref" href="#id30">5.3 Expected Build Output</a></h2> |
|---|
| 459 | <p>During the process of building Boost libraries, you can expect to |
|---|
| 460 | see some messages printed on the console. These may include</p> |
|---|
| 461 | <ul> |
|---|
| 462 | <li><p class="first">Notices about Boost library configuration—for example, the Regex |
|---|
| 463 | library outputs a message about ICU when built without Unicode |
|---|
| 464 | support, and the Python library may be skipped without error (but |
|---|
| 465 | with a notice) if you don't have Python installed.</p> |
|---|
| 466 | </li> |
|---|
| 467 | <li><p class="first">Messages from the build tool that report the number of targets |
|---|
| 468 | that were built or skipped. Don't be surprised if those numbers |
|---|
| 469 | don't make any sense to you; there are many targets per library.</p> |
|---|
| 470 | </li> |
|---|
| 471 | <li><p class="first">Build action messages describing what the tool is doing, which |
|---|
| 472 | look something like:</p> |
|---|
| 473 | <pre class="literal-block"> |
|---|
| 474 | <em>toolset-name</em>.c++ <em>long</em>/<em>path</em>/<em>to</em>/<em>file</em>/<em>being</em>/<em>built</em> |
|---|
| 475 | </pre> |
|---|
| 476 | </li> |
|---|
| 477 | <li><p class="first">Compiler warnings.</p> |
|---|
| 478 | </li> |
|---|
| 479 | </ul> |
|---|
| 480 | </div> |
|---|
| 481 | <div class="section" id="in-case-of-build-errors"> |
|---|
| 482 | <h2><a class="toc-backref" href="#id31">5.4 In Case of Build Errors</a></h2> |
|---|
| 483 | <p>The only error messages you see when building Boost—if any—should |
|---|
| 484 | be related to the IOStreams library's support of zip and bzip2 |
|---|
| 485 | formats as described <a class="reference external" href="../../libs/iostreams/doc/installation.html">here</a>. Install the relevant development |
|---|
| 486 | packages for libz and libbz2 if you need those features. Other |
|---|
| 487 | errors when building Boost libraries are cause for concern.</p> |
|---|
| 488 | <p>If it seems like the build system can't find your compiler and/or |
|---|
| 489 | linker, consider setting up a <tt class="docutils literal"><span class="pre">user-config.jam</span></tt> file as described |
|---|
| 490 | in the <a class="reference external" href="../../tools/build/index.html">Boost.Build documentation</a>. If that isn't your problem or |
|---|
| 491 | the <tt class="docutils literal"><span class="pre">user-config.jam</span></tt> file doesn't work for you, please address |
|---|
| 492 | questions about configuring Boost for your compiler to the |
|---|
| 493 | <a class="reference external" href="../../more/mailing_lists.htm#jamboost">Boost.Build mailing list</a>.</p> |
|---|
| 494 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 495 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 496 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 497 | </div> |
|---|
| 498 | </div> |
|---|
| 499 | <div class="section" id="link-your-program-to-a-boost-library"> |
|---|
| 500 | <h1><a class="toc-backref" href="#id32">6 Link Your Program to a Boost Library</a></h1> |
|---|
| 501 | <p>To demonstrate linking with a Boost binary library, we'll use the |
|---|
| 502 | following simple program that extracts the subject lines from |
|---|
| 503 | emails. It uses the <a class="reference external" href="../../libs/regex/index.html">Boost.Regex</a> library, which has a |
|---|
| 504 | separately-compiled binary component.</p> |
|---|
| 505 | <pre class="literal-block"> |
|---|
| 506 | #include <boost/regex.hpp> |
|---|
| 507 | #include <iostream> |
|---|
| 508 | #include <string> |
|---|
| 509 | |
|---|
| 510 | int main() |
|---|
| 511 | { |
|---|
| 512 | std::string line; |
|---|
| 513 | boost::regex pat( "^Subject: (Re: |Aw: )*(.*)" ); |
|---|
| 514 | |
|---|
| 515 | while (std::cin) |
|---|
| 516 | { |
|---|
| 517 | std::getline(std::cin, line); |
|---|
| 518 | boost::smatch matches; |
|---|
| 519 | if (boost::regex_match(line, matches, pat)) |
|---|
| 520 | std::cout << matches[2] << std::endl; |
|---|
| 521 | } |
|---|
| 522 | } |
|---|
| 523 | </pre> |
|---|
| 524 | <p>There are two main challenges associated with linking:</p> |
|---|
| 525 | <ol class="arabic simple"> |
|---|
| 526 | <li>Tool configuration, e.g. choosing command-line options or IDE |
|---|
| 527 | build settings.</li> |
|---|
| 528 | <li>Identifying the library binary, among all the build variants, |
|---|
| 529 | whose compile configuration is compatible with the rest of your |
|---|
| 530 | project.</li> |
|---|
| 531 | </ol> |
|---|
| 532 | <p>There are two main ways to link to libraries:</p> |
|---|
| 533 | <ol class="upperalpha"> |
|---|
| 534 | <li><p class="first">You can specify the full path to each library:</p> |
|---|
| 535 | <pre class="literal-block"> |
|---|
| 536 | $ c++ -I <em>path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_1</span></tt> example.cpp -o example <strong>\</strong> |
|---|
| 537 | <strong>~/boost/lib/libboost_regex-gcc34-mt-d-1_34.a</strong> |
|---|
| 538 | </pre> |
|---|
| 539 | </li> |
|---|
| 540 | <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="id12"><sup>2</sup></a> dropping the filename's leading <tt class="docutils literal"><span class="pre">lib</span></tt> and trailing |
|---|
| 541 | suffix (<tt class="docutils literal"><span class="pre">.a</span></tt> in this case):</p> |
|---|
| 542 | <pre class="literal-block"> |
|---|
| 543 | $ c++ -I <em>path/to/</em><tt class="docutils literal"><span class="pre">boost_1_34_1</span></tt> example.cpp -o example <strong>\</strong> |
|---|
| 544 | <strong>-L~/boost/lib/ -lboost_regex-gcc34-mt-d-1_34</strong> |
|---|
| 545 | </pre> |
|---|
| 546 | <p>As you can see, this method is just as terse as method A for one |
|---|
| 547 | library; it <em>really</em> pays off when you're using multiple |
|---|
| 548 | libraries from the same directory. Note, however, that if you |
|---|
| 549 | use this method with a library that has both static (<tt class="docutils literal"><span class="pre">.a</span></tt>) and |
|---|
| 550 | dynamic (<tt class="docutils literal"><span class="pre">.so</span></tt>) builds, the system may choose one |
|---|
| 551 | automatically for you unless you pass a special option such as |
|---|
| 552 | <tt class="docutils literal"><span class="pre">-static</span></tt> on the command line.</p> |
|---|
| 553 | </li> |
|---|
| 554 | </ol> |
|---|
| 555 | <p>In both cases above, the bold text is what you'd add to <a class="reference internal" href="#build-a-simple-program-using-boost">the |
|---|
| 556 | command lines we explored earlier</a>.</p> |
|---|
| 557 | <div class="section" id="library-naming"> |
|---|
| 558 | <h2><a class="toc-backref" href="#id33">6.1 Library Naming</a></h2> |
|---|
| 559 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 560 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 561 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 562 | <p>In order to choose the right binary for your build configuration |
|---|
| 563 | you need to know how Boost binaries are named. Each library |
|---|
| 564 | filename is composed of a common sequence of elements that describe |
|---|
| 565 | how it was built. For example, |
|---|
| 566 | <tt class="docutils literal"><span class="pre">libboost_regex-vc71-mt-d-1_34.lib</span></tt> can be broken down into the |
|---|
| 567 | following elements:</p> |
|---|
| 568 | <dl class="docutils"> |
|---|
| 569 | <dt><tt class="docutils literal"><span class="pre">lib</span></tt></dt> |
|---|
| 570 | <dd><em>Prefix</em>: except on Microsoft Windows, every Boost library |
|---|
| 571 | name begins with this string. On Windows, only ordinary static |
|---|
| 572 | libraries use the <tt class="docutils literal"><span class="pre">lib</span></tt> prefix; import libraries and DLLs do |
|---|
| 573 | not.<a class="footnote-reference" href="#distinct" id="id14"><sup>4</sup></a></dd> |
|---|
| 574 | <dt><tt class="docutils literal"><span class="pre">boost_regex</span></tt></dt> |
|---|
| 575 | <dd><em>Library name</em>: all boost library filenames begin with <tt class="docutils literal"><span class="pre">boost_</span></tt>.</dd> |
|---|
| 576 | <dt><tt class="docutils literal"><span class="pre">-vc71</span></tt></dt> |
|---|
| 577 | <dd><em>Toolset tag</em>: identifies the <a class="reference internal" href="#toolset">toolset</a> and version used to build |
|---|
| 578 | the binary.</dd> |
|---|
| 579 | <dt><tt class="docutils literal"><span class="pre">-mt</span></tt></dt> |
|---|
| 580 | <dd><em>Threading tag</em>: indicates that the library was |
|---|
| 581 | built with multithreading support enabled. Libraries built |
|---|
| 582 | without multithreading support can be identified by the absence |
|---|
| 583 | of <tt class="docutils literal"><span class="pre">-mt</span></tt>.</dd> |
|---|
| 584 | <dt><tt class="docutils literal"><span class="pre">-d</span></tt></dt> |
|---|
| 585 | <dd><p class="first"><em>ABI tag</em>: encodes details that affect the library's |
|---|
| 586 | interoperability with other compiled code. For each such |
|---|
| 587 | feature, a single letter is added to the tag:</p> |
|---|
| 588 | <blockquote> |
|---|
| 589 | <table border="1" class="docutils"> |
|---|
| 590 | <colgroup> |
|---|
| 591 | <col width="6%" /> |
|---|
| 592 | <col width="94%" /> |
|---|
| 593 | </colgroup> |
|---|
| 594 | <thead valign="bottom"> |
|---|
| 595 | <tr><th class="head">Key</th> |
|---|
| 596 | <th class="head">Use this library when:</th> |
|---|
| 597 | </tr> |
|---|
| 598 | </thead> |
|---|
| 599 | <tbody valign="top"> |
|---|
| 600 | <tr><td><tt class="docutils literal"><span class="pre">s</span></tt></td> |
|---|
| 601 | <td>linking statically to the C++ standard library and compiler runtime support |
|---|
| 602 | libraries.</td> |
|---|
| 603 | </tr> |
|---|
| 604 | <tr><td><tt class="docutils literal"><span class="pre">g</span></tt></td> |
|---|
| 605 | <td>using debug versions of the standard and runtime support libraries.</td> |
|---|
| 606 | </tr> |
|---|
| 607 | <tr><td><tt class="docutils literal"><span class="pre">y</span></tt></td> |
|---|
| 608 | <td>using a special <a class="reference external" href="../../libs/python/doc/building.html#variants">debug build of Python</a>.</td> |
|---|
| 609 | </tr> |
|---|
| 610 | <tr><td><tt class="docutils literal"><span class="pre">d</span></tt></td> |
|---|
| 611 | <td>building a debug version of your code.<a class="footnote-reference" href="#debug-abi" id="id15"><sup>5</sup></a></td> |
|---|
| 612 | </tr> |
|---|
| 613 | <tr><td><tt class="docutils literal"><span class="pre">p</span></tt></td> |
|---|
| 614 | <td>using the STLPort standard library rather than the default one supplied with |
|---|
| 615 | your compiler.</td> |
|---|
| 616 | </tr> |
|---|
| 617 | <tr><td><tt class="docutils literal"><span class="pre">n</span></tt></td> |
|---|
| 618 | <td>using STLPort's deprecated “native iostreams” feature.<a class="footnote-reference" href="#native" id="id16"><sup>6</sup></a></td> |
|---|
| 619 | </tr> |
|---|
| 620 | </tbody> |
|---|
| 621 | </table> |
|---|
| 622 | </blockquote> |
|---|
| 623 | <p class="last">For example, if you build a debug version of your code for use |
|---|
| 624 | with debug versions of the static runtime library and the |
|---|
| 625 | STLPort standard library in “native iostreams” mode, |
|---|
| 626 | the tag would be: <tt class="docutils literal"><span class="pre">-sgdpn</span></tt>. If none of the above apply, the |
|---|
| 627 | ABI tag is ommitted.</p> |
|---|
| 628 | </dd> |
|---|
| 629 | <dt><tt class="docutils literal"><span class="pre">-1_34</span></tt></dt> |
|---|
| 630 | <dd><em>Version tag</em>: the full Boost release number, with periods |
|---|
| 631 | replaced by underscores. For example, version 1.31.1 would be |
|---|
| 632 | tagged as "-1_31_1".</dd> |
|---|
| 633 | <dt><tt class="docutils literal"><span class="pre">.lib</span></tt></dt> |
|---|
| 634 | <dd><em>Extension</em>: determined according to the operating system's usual |
|---|
| 635 | convention. On most unix-style platforms the extensions are |
|---|
| 636 | <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 |
|---|
| 637 | libraries, respectively. On Windows, <tt class="docutils literal"><span class="pre">.dll</span></tt> indicates a shared |
|---|
| 638 | library and (except for static libraries built by the <tt class="docutils literal"><span class="pre">gcc</span></tt> |
|---|
| 639 | <a class="reference internal" href="#toolset">toolset</a>, whose names always end in <tt class="docutils literal"><span class="pre">.a</span></tt>) <tt class="docutils literal"><span class="pre">.lib</span></tt> indicates a |
|---|
| 640 | static or import library. Where supported by toolsets on unix |
|---|
| 641 | variants, a full version extension is added (e.g. ".so.1.34") and |
|---|
| 642 | a symbolic link to the library file, named without the trailing |
|---|
| 643 | version number, will also be created.</dd> |
|---|
| 644 | </dl> |
|---|
| 645 | <!-- .. _Boost.Build toolset names: toolset-name_ --> |
|---|
| 646 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 647 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 648 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 649 | </div> |
|---|
| 650 | <div class="section" id="test-your-program"> |
|---|
| 651 | <h2><a class="toc-backref" href="#id34">6.2 Test Your Program</a></h2> |
|---|
| 652 | <p>To test our subject extraction, we'll filter the following text |
|---|
| 653 | file. Copy it out of your browser and save it as <tt class="docutils literal"><span class="pre">jayne.txt</span></tt>:</p> |
|---|
| 654 | <pre class="literal-block"> |
|---|
| 655 | To: George Shmidlap |
|---|
| 656 | From: Rita Marlowe |
|---|
| 657 | Subject: Will Success Spoil Rock Hunter? |
|---|
| 658 | --- |
|---|
| 659 | See subject. |
|---|
| 660 | </pre> |
|---|
| 661 | <p>If you linked to a shared library, you may need to prepare some |
|---|
| 662 | platform-specific settings so that the system will be able to find |
|---|
| 663 | and load it when your program is run. Most platforms have an |
|---|
| 664 | environment variable to which you can add the directory containing |
|---|
| 665 | the library. On many platforms (Linux, FreeBSD) that variable is |
|---|
| 666 | <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 |
|---|
| 667 | 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> |
|---|
| 668 | and <tt class="docutils literal"><span class="pre">tcsh</span></tt>, you can adjust the variable as follows (again, don't |
|---|
| 669 | type the <tt class="docutils literal"><span class="pre">$</span></tt>—that represents the shell prompt):</p> |
|---|
| 670 | <pre class="literal-block"> |
|---|
| 671 | <strong>$</strong> <em>VARIABLE_NAME</em>=<em>path/to/lib/directory</em>:${<em>VARIABLE_NAME</em>} |
|---|
| 672 | <strong>$</strong> export <em>VARIABLE_NAME</em> |
|---|
| 673 | </pre> |
|---|
| 674 | <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> |
|---|
| 675 | <pre class="literal-block"> |
|---|
| 676 | <strong>$</strong> setenv <em>VARIABLE_NAME</em> <em>path/to/lib/directory</em>:${<em>VARIABLE_NAME</em>} |
|---|
| 677 | </pre> |
|---|
| 678 | <p>Once the necessary variable (if any) is set, you can run your |
|---|
| 679 | program as follows:</p> |
|---|
| 680 | <pre class="literal-block"> |
|---|
| 681 | <strong>$</strong> <em>path</em>/<em>to</em>/<em>compiled</em>/example < <em>path</em>/<em>to</em>/jayne.txt |
|---|
| 682 | </pre> |
|---|
| 683 | <p>The program should respond with the email subject, “Will Success |
|---|
| 684 | Spoil Rock Hunter?”</p> |
|---|
| 685 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 686 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 687 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 688 | </div> |
|---|
| 689 | </div> |
|---|
| 690 | <div class="section" id="conclusion-and-further-resources"> |
|---|
| 691 | <h1><a class="toc-backref" href="#id35">7 Conclusion and Further Resources</a></h1> |
|---|
| 692 | <p>This concludes your introduction to Boost and to integrating it |
|---|
| 693 | with your programs. As you start using Boost in earnest, there are |
|---|
| 694 | surely a few additional points you'll wish we had covered. One day |
|---|
| 695 | we may have a “Book 2 in the Getting Started series” that addresses |
|---|
| 696 | them. Until then, we suggest you pursue the following resources. |
|---|
| 697 | If you can't find what you need, or there's anything we can do to |
|---|
| 698 | make this document clearer, please post it to the <a class="reference external" href="../../more/mailing_lists.htm#users">Boost Users' |
|---|
| 699 | mailing list</a>.</p> |
|---|
| 700 | <ul class="simple"> |
|---|
| 701 | <li><a class="reference external" href="../../tools/build/v2/index.html">Boost.Build reference manual</a></li> |
|---|
| 702 | <li><a class="reference external" href="../../tools/jam/index.html">Boost.Jam reference manual</a></li> |
|---|
| 703 | <li><a class="reference external" href="../../more/mailing_lists.htm#users">Boost Users' mailing list</a></li> |
|---|
| 704 | <li><a class="reference external" href="../../more/mailing_lists.htm#jamboost">Boost.Build mailing list</a></li> |
|---|
| 705 | <li><a class="reference external" href="http://www.crystalclearsoftware.com/cgi-bin/boost_wiki/wiki.pl?Boost.Build_V2">Boost.Build Wiki</a></li> |
|---|
| 706 | <li><a class="reference external" href="../../libs/index.html">Index of all Boost library documentation</a></li> |
|---|
| 707 | </ul> |
|---|
| 708 | <div class="admonition-onward admonition"> |
|---|
| 709 | <p class="first admonition-title">Onward</p> |
|---|
| 710 | <blockquote class="epigraph last"> |
|---|
| 711 | <p>Good luck, and have fun!</p> |
|---|
| 712 | <p class="attribution">—the Boost Developers</p> |
|---|
| 713 | </blockquote> |
|---|
| 714 | </div> |
|---|
| 715 | <hr class="docutils" /> |
|---|
| 716 | <table class="docutils footnote" frame="void" id="packagers" rules="none"> |
|---|
| 717 | <colgroup><col class="label" /><col /></colgroup> |
|---|
| 718 | <tbody valign="top"> |
|---|
| 719 | <tr><td class="label"><a class="fn-backref" href="#id2">[1]</a></td><td><p class="first">If developers of Boost packages would like to work |
|---|
| 720 | with us to make sure these instructions can be used with their |
|---|
| 721 | packages, we'd be glad to help. Please make your interest known |
|---|
| 722 | to the <a class="reference external" href="../../more/mailing_lists.htm#main">Boost developers' list</a>.</p> |
|---|
| 723 | </td></tr> |
|---|
| 724 | </tbody> |
|---|
| 725 | </table> |
|---|
| 726 | <table class="docutils footnote" frame="void" id="lowercase-l" rules="none"> |
|---|
| 727 | <colgroup><col class="label" /><col /></colgroup> |
|---|
| 728 | <tbody valign="top"> |
|---|
| 729 | <tr><td class="label"><a class="fn-backref" href="#id12">[2]</a></td><td>That option is a dash followed by a lowercase “L” |
|---|
| 730 | character, which looks very much like a numeral 1 in some fonts.</td></tr> |
|---|
| 731 | </tbody> |
|---|
| 732 | </table> |
|---|
| 733 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 734 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 735 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 736 | <table class="docutils footnote" frame="void" id="warnings" rules="none"> |
|---|
| 737 | <colgroup><col class="label" /><col /></colgroup> |
|---|
| 738 | <tbody valign="top"> |
|---|
| 739 | <tr><td class="label"><a class="fn-backref" href="#id5">[3]</a></td><td>Remember that warnings are specific to each compiler |
|---|
| 740 | implementation. The developer of a given Boost library might |
|---|
| 741 | not have access to your compiler. Also, some warnings are |
|---|
| 742 | extremely difficult to eliminate in generic code, to the point |
|---|
| 743 | where it's not worth the trouble. Finally, some compilers don't |
|---|
| 744 | have any source code mechanism for suppressing warnings.</td></tr> |
|---|
| 745 | </tbody> |
|---|
| 746 | </table> |
|---|
| 747 | <table class="docutils footnote" frame="void" id="distinct" rules="none"> |
|---|
| 748 | <colgroup><col class="label" /><col /></colgroup> |
|---|
| 749 | <tbody valign="top"> |
|---|
| 750 | <tr><td class="label"><a class="fn-backref" href="#id14">[4]</a></td><td>This convention distinguishes the static version of |
|---|
| 751 | a Boost library from the import library for an |
|---|
| 752 | identically-configured Boost DLL, which would otherwise have the |
|---|
| 753 | same name.</td></tr> |
|---|
| 754 | </tbody> |
|---|
| 755 | </table> |
|---|
| 756 | <table class="docutils footnote" frame="void" id="debug-abi" rules="none"> |
|---|
| 757 | <colgroup><col class="label" /><col /></colgroup> |
|---|
| 758 | <tbody valign="top"> |
|---|
| 759 | <tr><td class="label"><a class="fn-backref" href="#id15">[5]</a></td><td>These libraries were compiled without optimization |
|---|
| 760 | or inlining, with full debug symbols enabled, and without |
|---|
| 761 | <tt class="docutils literal"><span class="pre">NDEBUG</span></tt> <tt class="docutils literal"><span class="pre">#define</span></tt>d. Although it's true that sometimes |
|---|
| 762 | these choices don't affect binary compatibility with other |
|---|
| 763 | compiled code, you can't count on that with Boost libraries.</td></tr> |
|---|
| 764 | </tbody> |
|---|
| 765 | </table> |
|---|
| 766 | <table class="docutils footnote" frame="void" id="native" rules="none"> |
|---|
| 767 | <colgroup><col class="label" /><col /></colgroup> |
|---|
| 768 | <tbody valign="top"> |
|---|
| 769 | <tr><td class="label"><a class="fn-backref" href="#id16">[6]</a></td><td>This feature of STLPort is deprecated because it's |
|---|
| 770 | impossible to make it work transparently to the user; we don't |
|---|
| 771 | recommend it.</td></tr> |
|---|
| 772 | </tbody> |
|---|
| 773 | </table> |
|---|
| 774 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 775 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 776 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 777 | <!-- This file contains all the definitions that need to be updated --> |
|---|
| 778 | <!-- for each new release of Boost. --> |
|---|
| 779 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 780 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 781 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 782 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 783 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 784 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 785 | <!-- Copyright David Abrahams 2006. Distributed under the Boost --> |
|---|
| 786 | <!-- Software License, Version 1.0. (See accompanying --> |
|---|
| 787 | <!-- file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) --> |
|---|
| 788 | </div> |
|---|
| 789 | </div> |
|---|
| 790 | </body> |
|---|
| 791 | </html> |
|---|