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