1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
4 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
5 <title>Tutorial</title>
6 <link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
7 <meta name="generator" content="DocBook XSL Stylesheets V1.79.1">
8 <link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
9 <link rel="up" href="../bbv2.html" title="Chapter 49. Boost.Build User Manual">
10 <link rel="prev" href="../bbv2.html" title="Chapter 49. Boost.Build User Manual">
11 <link rel="next" href="overview.html" title="Overview">
13 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
14 <table cellpadding="2" width="100%"><tr>
15 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
16 <td align="center"><a href="../../../index.html">Home</a></td>
17 <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
18 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
19 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
20 <td align="center"><a href="../../../more/index.htm">More</a></td>
23 <div class="spirit-nav">
24 <a accesskey="p" href="../bbv2.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../bbv2.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overview.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>
27 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
28 <a name="bbv2.tutorial"></a>Tutorial</h2></div></div></div>
29 <div class="toc"><dl class="toc">
30 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.hello">Hello, world</a></span></dt>
31 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.properties">Properties</a></span></dt>
32 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.hierarchy">Project Hierarchies</a></span></dt>
33 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.libs">Dependent Targets</a></span></dt>
34 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.linkage">Static and shared libraries</a></span></dt>
35 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.conditions">Conditions and alternatives</a></span></dt>
36 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.prebuilt">Prebuilt targets</a></span></dt>
39 This section will guide you though the most basic features of Boost.Build.
40 We will start with the “Hello, world” example, learn how
41 to use libraries, and finish with testing and installing features.
44 <div class="titlepage"><div><div><h3 class="title">
45 <a name="bbv2.tutorial.hello"></a>Hello, world</h3></div></div></div>
47 The simplest project that Boost.Build can construct is stored in
48 <code class="filename">example/hello/</code> directory. The project is described by
49 a file called <code class="filename">Jamroot</code> that contains:
52 <pre class="programlisting">
53 exe hello <span class="special">:</span> hello.cpp <span class="special">;</span>
57 Even with this simple setup, you can do some interesting things. First of
58 all, just invoking <span class="command"><strong>b2</strong></span> will build the <code class="filename">hello
59 </code> executable by compiling and linking <code class="filename">hello.cpp
60 </code>. By default, the debug variant is built. Now, to build the release
61 variant of <code class="filename">hello</code>, invoke
69 Note that the debug and release variants are created in different directories,
70 so you can switch between variants or even build multiple variants at
71 once, without any unnecessary recompilation. Let us extend the example by
72 adding another line to our project's <code class="filename">Jamroot</code>:
75 <pre class="programlisting">
76 exe hello2 <span class="special">:</span> hello.cpp <span class="special">;</span>
80 Now let us build both the debug and release variants of our project again:
88 Note that two variants of <code class="filename">hello2</code> are linked. Since we
89 have already built both variants of <code class="filename">hello</code>, hello.cpp
90 will not be recompiled; instead the existing object files will just be
91 linked into the corresponding variants of <code class="filename">hello2</code>. Now
92 let us remove all the built products:
96 b2 --clean debug release
100 It is also possible to build or clean specific targets. The following two
101 commands, respectively, build or clean only the debug version of
102 <code class="filename">hello2</code>.
112 <div class="section">
113 <div class="titlepage"><div><div><h3 class="title">
114 <a name="bbv2.tutorial.properties"></a>Properties</h3></div></div></div>
115 <div class="toc"><dl class="toc">
116 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.properties.requirements">Build Requests and Target Requirements</a></span></dt>
117 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.properties.project_attributes">Project Attributes</a></span></dt>
120 To represent aspects of target configuration such as
121 debug and release variants, or single- and multi-threaded
122 builds portably, Boost.Build uses <em class="firstterm">features</em> with
123 associated <em class="firstterm">values</em>. For
124 example, the <code class="computeroutput">debug-symbols</code> feature can have a value of <code class="computeroutput">on</code> or
125 <code class="computeroutput">off</code>. A <em class="firstterm">property</em> is just a (feature,
126 value) pair. When a user initiates a build, Boost.Build
127 automatically translates the requested properties into appropriate
128 command-line flags for invoking toolset components like compilers
132 There are many built-in features that can be combined to
133 produce arbitrary build configurations. The following command
134 builds the project's <code class="computeroutput">release</code> variant with inlining
135 disabled and debug symbols enabled:
138 b2 release inlining=off debug-symbols=on
143 Properties on the command-line are specified with the syntax:
147 <em class="replaceable"><code>feature-name</code></em>=<em class="replaceable"><code>feature-value</code></em>
152 The <code class="option">release</code> and <code class="option">debug</code> that we have seen
153 in <span class="command"><strong>b2</strong></span> invocations are just a shorthand way to specify
154 values of the <code class="varname">variant</code> feature. For example, the
155 command above could also have been written this way:
159 b2 variant=release inlining=off debug-symbols=on
164 <code class="varname">variant</code> is so commonly-used that it has been given
165 special status as an <em class="firstterm">implicit</em> feature—
166 Boost.Build will deduce its identity just from the name of one of its
170 A complete description of features can be found in <a class="xref" href="reference.html#bbv2.reference.features" title="Features and properties">the section called “Features and properties”</a>.
172 <div class="section">
173 <div class="titlepage"><div><div><h4 class="title">
174 <a name="bbv2.tutorial.properties.requirements"></a>Build Requests and Target Requirements</h4></div></div></div>
176 The set of properties specified on the command line constitutes
177 a <em class="firstterm">build request</em>—a description of
178 the desired properties for building the requested targets (or,
179 if no targets were explicitly requested, the project in the
180 current directory). The <span class="emphasis"><em>actual</em></span>
181 properties used for building targets are typically a
182 combination of the build request and properties derived from
183 the project's <code class="filename">Jamroot</code> (and its other
184 Jamfiles, as described in <a class="xref" href="tutorial.html#bbv2.tutorial.hierarchy" title="Project Hierarchies">the section called “Project Hierarchies”</a>). For example, the
185 locations of <code class="computeroutput">#include</code>d header files are normally
186 not specified on the command-line, but described in
187 Jamfiles as <em class="firstterm">target
188 requirements</em> and automatically combined with the
189 build request for those targets. Multithread-enabled
190 compilation is another example of a typical target
191 requirement. The Jamfile fragment below
192 illustrates how these requirements might be specified.
194 <pre class="programlisting">
196 <span class="special">:</span> hello.cpp
197 <span class="special">:</span> <include>boost <threading>multi
198 <span class="special">;</span>
201 When <code class="filename">hello</code> is built, the two requirements specified
202 above will always be present. If the build request given on the
203 <span class="command"><strong>b2</strong></span> command-line explictly contradicts a target's
204 requirements, the target requirements usually override (or, in the case
205 of “free”” features like
206 <code class="varname"><include></code>,
207 <a href="#ftn.idp636449168" class="footnote" name="idp636449168"><sup class="footnote">[16]</sup></a>
208 augment) the build request.
210 <div class="tip"><table border="0" summary="Tip">
212 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
213 <th align="left">Tip</th>
215 <tr><td align="left" valign="top"><p>
216 The value of the <code class="varname"><include></code> feature is
217 relative to the location of <code class="filename">Jamroot</code> where it is
222 <div class="section">
223 <div class="titlepage"><div><div><h4 class="title">
224 <a name="bbv2.tutorial.properties.project_attributes"></a>Project Attributes</h4></div></div></div>
226 If we want the same requirements for our other target,
227 <code class="filename">hello2</code>, we could simply duplicate them. However,
228 as projects grow, that approach leads to a great deal of repeated
229 boilerplate in Jamfiles.
231 Fortunately, there's a better way. Each project can specify a set of
232 <em class="firstterm">attributes</em>, including requirements:
235 <pre class="programlisting">
237 <span class="special">:</span> requirements <include>/home/ghost/Work/boost <threading>multi
238 <span class="special">;</span>
240 exe hello <span class="special">:</span> hello.cpp <span class="special">;</span>
241 exe hello2 <span class="special">:</span> hello.cpp <span class="special">;</span></pre>
244 The effect would be as if we specified the same requirement for both
245 <code class="filename">hello</code> and <code class="filename">hello2</code>.
249 <div class="section">
250 <div class="titlepage"><div><div><h3 class="title">
251 <a name="bbv2.tutorial.hierarchy"></a>Project Hierarchies</h3></div></div></div>
253 So far we have only considered examples with one project, with
254 one user-written Boost.Jam file, <code class="filename">Jamroot</code>. A typical
255 large codebase would be composed of many projects organized into a tree.
256 The top of the tree is called the <em class="firstterm">project root</em>.
257 Every subproject is defined by a file called <code class="filename">Jamfile</code>
258 in a descendant directory of the project root. The parent project of a
259 subproject is defined by the nearest <code class="filename">Jamfile</code> or
260 <code class="filename">Jamroot</code> file in an ancestor directory. For example,
261 in the following directory layout:
283 the project root is <code class="filename">top/</code>. The projects in
284 <code class="filename">top/app/</code> and <code class="filename">top/util/foo/</code> are
285 immediate children of the root project.
288 <div class="note"><table border="0" summary="Note">
290 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
291 <th align="left">Note</th>
293 <tr><td align="left" valign="top"><p>
294 When we refer to a “Jamfile,” set in normal
295 type, we mean a file called either
296 <code class="filename">Jamfile</code> or
297 <code class="filename">Jamroot</code>. When we need to be more
298 specific, the filename will be set as
299 “<code class="filename">Jamfile</code>” or
300 “<code class="filename">Jamroot</code>.”
306 Projects inherit all attributes (such as requirements)
307 from their parents. Inherited requirements are combined with
308 any requirements specified by the subproject.
309 For example, if <code class="filename">top/Jamroot</code> has
312 <pre class="programlisting">
313 <include>/home/ghost/local
317 in its requirements, then all of its subprojects will have it
318 in their requirements, too. Of course, any project can add
319 include paths to those specified by its parents. <a href="#ftn.idp636477376" class="footnote" name="idp636477376"><sup class="footnote">[17]</sup></a>
320 More details can be found in
321 <a class="xref" href="overview.html#bbv2.overview.projects" title="Projects">the section called “Projects”</a>.
324 Invoking <span class="command"><strong>b2</strong></span> without explicitly specifying
325 any targets on the command line builds the project rooted in the
326 current directory. Building a project does not automatically
327 cause its subprojects to be built unless the parent project's
328 Jamfile explicitly requests it. In our example,
329 <code class="filename">top/Jamroot</code> might contain:
332 <pre class="programlisting">
333 build-project app <span class="special">;</span>
337 which would cause the project in <code class="filename">top/app/</code>
338 to be built whenever the project in <code class="filename">top/</code> is
339 built. However, targets in <code class="filename">top/util/foo/</code>
340 will be built only if they are needed by targets in
341 <code class="filename">top/</code> or <code class="filename">top/app/</code>.
344 <div class="section">
345 <div class="titlepage"><div><div><h3 class="title">
346 <a name="bbv2.tutorial.libs"></a>Dependent Targets</h3></div></div></div>
348 When building a target <code class="filename">X</code> that depends on first
349 building another target <code class="filename">Y</code> (such as a
350 library that must be linked with <em class="firstterm">X</em>),
351 <code class="filename">Y</code> is called a
352 <em class="firstterm">dependency</em> of <code class="filename">X</code> and
353 <code class="filename">X</code> is termed a
354 <em class="firstterm">dependent</em> of <code class="filename">Y</code>.
356 <p>To get a feeling of target dependencies, let's continue the
357 above example and see how <code class="filename">top/app/Jamfile</code> can
358 use libraries from <code class="filename">top/util/foo</code>. If
359 <code class="filename">top/util/foo/Jamfile</code> contains
362 <pre class="programlisting">
363 lib bar <span class="special">:</span> bar.cpp <span class="special">;</span>
367 then to use this library in <code class="filename">top/app/Jamfile</code>, we can
371 <pre class="programlisting">
372 exe app <span class="special">:</span> app.cpp ../util/foo//bar <span class="special">;</span>
376 While <code class="computeroutput">app.cpp</code> refers to a regular source file,
377 <code class="computeroutput">../util/foo//bar</code> is a reference to another target:
378 a library <code class="filename">bar</code> declared in the Jamfile at
379 <code class="filename">../util/foo</code>.
381 <div class="tip"><table border="0" summary="Tip">
383 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
384 <th align="left">Tip</th>
386 <tr><td align="left" valign="top"><p>Some other build system have special syntax for listing dependent
387 libraries, for example <code class="varname">LIBS</code> variable. In Boost.Build,
388 you just add the library to the list of sources.
391 <p>Suppose we build <code class="filename">app</code> with:
394 b2 app optimization=full define=USE_ASM
397 Which properties will be used to build <code class="computeroutput">foo</code>? The answer is
398 that some features are
399 <em class="firstterm">propagated</em>—Boost.Build attempts to use
400 dependencies with the same value of propagated features. The
401 <code class="varname"><optimization></code> feature is propagated, so both
402 <code class="filename">app</code> and <code class="filename">foo</code> will be compiled
403 with full optimization. But <code class="varname"><define></code> is not
404 propagated: its value will be added as-is to the compiler flags for
405 <code class="filename">a.cpp</code>, but won't affect <code class="filename">foo</code>.
408 Let's improve this project further. The library probably has some headers
409 that must be used when compiling <code class="filename">app.cpp</code>. We could
410 manually add the necessary <code class="computeroutput">#include</code> paths to
411 <code class="filename">app</code>'s requirements as values of the
412 <code class="varname"><include> </code> feature, but then this work will be
413 repeated for all programs that use <code class="filename">foo</code>. A better
414 solution is to modify <code class="filename">util/foo/Jamfile</code> in this way:
417 <pre class="programlisting">
419 <span class="special">:</span> usage-requirements <include>.
420 <span class="special">;</span>
422 lib foo <span class="special">:</span> foo.cpp <span class="special">;</span></pre>
425 Usage requirements are applied not to the target being declared but to its
426 dependents. In this case, <code class="literal"><include>.</code> will be
427 applied to all targets that directly depend on <code class="filename">foo</code>.
430 Another improvement is using symbolic identifiers to refer to the library,
431 as opposed to <code class="filename">Jamfile</code> location. In a large project, a
432 library can be used by many targets, and if they all use <code class="filename">Jamfile
433 </code> location, a change in directory organization entails much
434 work. The solution is to use project ids—symbolic names not tied to
435 directory layout. First, we need to assign a project id by adding this
436 code to <code class="filename">Jamroot</code>:
438 <pre class="programlisting">
439 use-project /library-example/foo <span class="special">:</span> util/foo <span class="special">;</span></pre>
441 Second, we modify <code class="filename">app/Jamfile</code> to use the project id:
443 <pre class="programlisting">
444 exe app : app.cpp /library-example/foo//bar ;</pre>
447 The <code class="filename">/library-example/foo//bar</code> syntax is used to refer
448 to the target <code class="filename">bar</code> in the project with id <code class="filename">
449 /library-example/foo</code>. We've achieved our goal—if the
450 library is moved to a different directory, only <code class="filename">Jamroot
451 </code> must be modified. Note that project ids are global—two
452 Jamfiles are not allowed to assign the same project id to different
455 <div class="tip"><table border="0" summary="Tip">
457 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
458 <th align="left">Tip</th>
460 <tr><td align="left" valign="top">
461 <p>If you want all applications in some project to link to a certain
462 library, you can avoid having to specify directly the sources of
463 every target by using the <code class="varname"><library></code> property.
464 For example, if <code class="filename">/boost/filesystem//fs</code> should be
465 linked to all applications in your project, you can add
466 <code class="computeroutput"><library>/boost/filesystem//fs</code> to the project's
467 requirements, like this:
469 <pre class="programlisting">
471 <span class="special">:</span> requirements <library>/boost/filesystem//fs
472 <span class="special">;</span></pre>
476 <div class="section">
477 <div class="titlepage"><div><div><h3 class="title">
478 <a name="bbv2.tutorial.linkage"></a>Static and shared libraries</h3></div></div></div>
480 Libraries can be either <span class="emphasis"><em>static</em></span>, which means they are
481 included in executable files that use them, or <span class="emphasis"><em>shared</em></span>
482 (a.k.a. <span class="emphasis"><em>dynamic</em></span>), which are only referred to from
483 executables, and must be available at run time. Boost.Build can create and
487 The kind of library produced from a <code class="computeroutput">lib</code> target is determined
488 by the value of the <code class="varname">link</code> feature. Default value is
489 <code class="literal">shared</code>, and to build a static library, the value should
490 be <code class="literal">static</code>. You can request a static build either on the
493 <pre class="programlisting">b2 link=static</pre>
495 or in the library's requirements:
497 <pre class="programlisting">lib l <span class="special">:</span> l.cpp <span class="special">:</span> <link>static <span class="special">;</span></pre>
501 We can also use the <code class="varname"><link></code> property to express
502 linking requirements on a per-target basis. For example, if a particular
503 executable can be correctly built only with the static version of a
504 library, we can qualify the executable's <a class="link" href="reference.html#bbv2.reference.targets.references">target reference</a> to the
510 <pre class="programlisting">
511 exe important <span class="special">:</span> main.cpp helpers/<link>static <span class="special">;</span></pre>
514 No matter what arguments are specified on the <span class="command"><strong>b2</strong></span>
515 command line, <code class="filename">important</code> will only be linked with the
516 static version of <code class="filename">helpers</code>.
519 Specifying properties in target references is especially useful if you use
520 a library defined in some other project (one you can't change) but you
521 still want static (or dynamic) linking to that library in all cases. If
522 that library is used by many targets, you <span class="emphasis"><em>could</em></span> use
523 target references everywhere:
526 <pre class="programlisting">
527 exe e1 <span class="special">:</span> e1.cpp /other_project//bar/<link>static <span class="special">;</span>
528 exe e10 <span class="special">:</span> e10.cpp /other_project//bar/<link>static <span class="special">;</span></pre>
531 but that's far from being convenient. A better approach is to introduce a
532 level of indirection. Create a local <span class="type">alias</span> target that refers
533 to the static (or dynamic) version of <code class="filename">foo</code>:
536 <pre class="programlisting">
537 alias foo : /other_project//bar/<link>static ;
538 exe e1 : e1.cpp foo ;
539 exe e10 : e10.cpp foo ;</pre>
542 The <a class="link" href="tasks.html#bbv2.tasks.alias" title="Alias">alias</a> rule is specifically
543 used to rename a reference to a target and possibly change the
548 <div class="tip"><table border="0" summary="Tip">
550 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
551 <th align="left">Tip</th>
553 <tr><td align="left" valign="top">
555 When one library uses another, you put the second library in the source
556 list of the first. For example:
558 <pre class="programlisting">
559 lib utils <span class="special">:</span> utils.cpp /boost/filesystem//fs <span class="special">;</span>
560 lib core <span class="special">:</span> core.cpp utils <span class="special">;</span>
561 exe app <span class="special">:</span> app.cpp core <span class="special">;</span></pre>
563 This works no matter what kind of linking is used. When <code class="filename">core
564 </code> is built as a shared library, links <code class="filename">utils
565 </code> directly into it. Static libraries can't link to other
566 libraries, so when <code class="filename">core</code> is built as a static
567 library, its dependency on <code class="filename">utils</code> is passed along to
568 <code class="filename">core</code>'s dependents, causing <code class="filename">app</code>
569 to be linked with both <code class="filename">core</code> and <code class="filename">utils
574 <div class="note"><table border="0" summary="Note">
576 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
577 <th align="left">Note</th>
579 <tr><td align="left" valign="top"><p>
580 (Note for non-UNIX system). Typically, shared libraries must be
581 installed to a directory in the dynamic linker's search path. Otherwise,
582 applications that use shared libraries can't be started. On Windows, the
583 dynamic linker's search path is given by the <code class="envar">PATH</code>
584 environment variable. This restriction is lifted when you use
585 Boost.Build testing facilities—the <code class="envar">PATH</code> variable
586 will be automatically adjusted before running the executable.
591 <div class="section">
592 <div class="titlepage"><div><div><h3 class="title">
593 <a name="bbv2.tutorial.conditions"></a>Conditions and alternatives</h3></div></div></div>
595 Sometimes, particular relationships need to be maintained among a target's
596 build properties. For example, you might want to set specific <code class="computeroutput">
597 #define</code> when a library is built as shared, or when a target's
598 <code class="computeroutput">release</code> variant is built. This can be achieved using
599 <em class="firstterm">conditional requirements</em>.
602 <pre class="programlisting">
603 lib network <span class="special">:</span> network.cpp
604 <span class="special">:</span> <span class="bold"><strong><link>shared:<define>NETWORK_LIB_SHARED</strong></span>
605 <variant>release:<define>EXTRA_FAST
606 <span class="special">;</span></pre>
609 In the example above, whenever <code class="filename">network</code> is built with
610 <code class="computeroutput"><link>shared</code>, <code class="computeroutput"><define>NETWORK_LIB_SHARED
611 </code> will be in its properties, too. Also, whenever its release variant
612 is built, <code class="computeroutput"><define>EXTRA_FAST</code> will appear in its
616 Sometimes the ways a target is built are so different that describing them
617 using conditional requirements would be hard. For example, imagine that a
618 library actually uses different source files depending on the toolset used
619 to build it. We can express this situation using <em class="firstterm">target
622 <pre class="programlisting">
623 lib demangler <span class="special">:</span> dummy_demangler.cpp <span class="special">;</span> <span class="comment"># alternative 1</span>
624 lib demangler <span class="special">:</span> demangler_gcc.cpp <span class="special">:</span> <toolset>gcc <span class="special">;</span> <span class="comment"># alternative 2</span>
625 lib demangler <span class="special">:</span> demangler_msvc.cpp <span class="special">:</span> <toolset>msvc <span class="special">;</span> <span class="comment"># alternative 3</span></pre>
627 When building <code class="filename">demangler</code>, Boost.Build will compare
628 requirements for each alternative with build properties to find the best
629 match. For example, when building with <code class="computeroutput"><toolset>gcc</code>
630 alternative 2, will be selected, and when building with
631 <code class="computeroutput"><toolset>msvc</code> alternative 3 will be selected. In all
632 other cases, the most generic alternative 1 will be built.
635 <div class="section">
636 <div class="titlepage"><div><div><h3 class="title">
637 <a name="bbv2.tutorial.prebuilt"></a>Prebuilt targets</h3></div></div></div>
639 To link to libraries whose build instructions aren't given in a Jamfile,
640 you need to create <code class="computeroutput">lib</code> targets with an appropriate
641 <code class="varname">file</code> property. Target alternatives can be used to
642 associate multiple library files with a single conceptual target. For
645 <pre class="programlisting">
646 <span class="comment"># util/lib2/Jamfile</span>
648 <span class="special">:</span>
649 <span class="special">:</span> <file>lib2_release.a <variant>release
650 <span class="special">;</span>
653 <span class="special">:</span>
654 <span class="special">:</span> <file>lib2_debug.a <variant>debug
655 <span class="special">;</span></pre>
658 This example defines two alternatives for <code class="filename">lib2</code>, and
659 for each one names a prebuilt file. Naturally, there are no sources.
660 Instead, the <code class="varname"><file></code> feature is used to specify
664 Once a prebuilt target has been declared, it can be used just like any
668 <pre class="programlisting">
669 exe app <span class="special">:</span> app.cpp ../util/lib2//lib2 <span class="special">;</span></pre>
672 As with any target, the alternative selected depends on the properties
673 propagated from <code class="filename">lib2</code>'s dependents. If we build the
674 release and debug versions of <code class="filename">app</code> it will be linked
675 with <code class="filename">lib2_release.a</code> and <code class="filename">lib2_debug.a
676 </code>, respectively.
679 System libraries—those that are automatically found by the toolset
680 by searching through some set of predetermined paths—should be
681 declared almost like regular ones:
684 <pre class="programlisting">
685 lib pythonlib <span class="special">:</span> <span class="special">:</span> <name>python22 <span class="special">;</span></pre>
688 We again don't specify any sources, but give a <code class="varname">name</code>
689 that should be passed to the compiler. If the gcc toolset were used to
690 link an executable target to <code class="filename">pythonlib</code>,
691 <code class="option">-lpython22</code> would appear in the command line (other
692 compilers may use different options).
695 We can also specify where the toolset should look for the library:
698 <pre class="programlisting">
699 lib pythonlib <span class="special">:</span> <span class="special">:</span> <name>python22 <search>/opt/lib <span class="special">;</span></pre>
702 And, of course, target alternatives can be used in the usual way:
705 <pre class="programlisting">
706 lib pythonlib <span class="special">:</span> <span class="special">:</span> <name>python22 <variant>release <span class="special">;</span>
707 lib pythonlib <span class="special">:</span> <span class="special">:</span> <name>python22_d <variant>debug <span class="special">;</span></pre>
711 A more advanced use of prebuilt targets is described in <a class="xref" href="faq.html#bbv2.recipies.site-config" title="Targets in site-config.jam">the section called “Targets in site-config.jam”</a>.
714 <div class="footnotes">
715 <br><hr style="width:100; text-align:left;margin-left: 0">
716 <div id="ftn.idp636449168" class="footnote"><p><a href="#idp636449168" class="para"><sup class="para">[16] </sup></a>
717 See <a class="xref" href="reference.html#bbv2.reference.features.attributes" title="Feature Attributes">the section called “Feature Attributes”</a>
719 <div id="ftn.idp636477376" class="footnote"><p><a href="#idp636477376" class="para"><sup class="para">[17] </sup></a>Many
720 features will be overridden,
721 rather than added-to, in subprojects. See <a class="xref" href="reference.html#bbv2.reference.features.attributes" title="Feature Attributes">the section called “Feature Attributes”</a> for more
722 information</p></div>
725 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
726 <td align="left"></td>
727 <td align="right"><div class="copyright-footer"></div></td>
730 <div class="spirit-nav">
731 <a accesskey="p" href="../bbv2.html"><img src="../../../doc/src/images/prev.png" alt="Prev"></a><a accesskey="u" href="../bbv2.html"><img src="../../../doc/src/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../doc/src/images/home.png" alt="Home"></a><a accesskey="n" href="overview.html"><img src="../../../doc/src/images/next.png" alt="Next"></a>