3 <meta http-equiv="Content-Type" content="text/html; charset=US-ASCII">
4 <title>Tutorial</title>
5 <link rel="stylesheet" href="../../../doc/src/boostbook.css" type="text/css">
6 <meta name="generator" content="DocBook XSL Stylesheets V1.78.1">
7 <link rel="home" href="../index.html" title="The Boost C++ Libraries BoostBook Documentation Subset">
8 <link rel="up" href="../bbv2.html" title="Chapter 43. Boost.Build V2 User Manual">
9 <link rel="prev" href="installation.html" title="Installation">
10 <link rel="next" href="overview.html" title="Overview">
12 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
13 <table cellpadding="2" width="100%"><tr>
14 <td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../boost.png"></td>
15 <td align="center"><a href="../../../index.html">Home</a></td>
16 <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
17 <td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
18 <td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
19 <td align="center"><a href="../../../more/index.htm">More</a></td>
22 <div class="spirit-nav">
23 <a accesskey="p" href="installation.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>
26 <div class="titlepage"><div><div><h2 class="title" style="clear: both">
27 <a name="bbv2.tutorial"></a>Tutorial</h2></div></div></div>
28 <div class="toc"><dl class="toc">
29 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.hello">Hello, world</a></span></dt>
30 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.properties">Properties</a></span></dt>
31 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.hierarchy">Project Hierarchies</a></span></dt>
32 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.libs">Dependent Targets</a></span></dt>
33 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.linkage">Static and shared libaries</a></span></dt>
34 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.conditions">Conditions and alternatives</a></span></dt>
35 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.prebuilt">Prebuilt targets</a></span></dt>
38 This section will guide you though the most basic features of Boost.Build
39 V2. We will start with the “Hello, world” example, learn how
40 to use libraries, and finish with testing and installing features.
43 <div class="titlepage"><div><div><h3 class="title">
44 <a name="bbv2.tutorial.hello"></a>Hello, world</h3></div></div></div>
46 The simplest project that Boost.Build can construct is stored in
47 <code class="filename">example/hello/</code> directory. The project is described by
48 a file called <code class="filename">Jamroot</code> that contains:
51 <pre class="programlisting">
52 exe hello <span class="special">:</span> hello.cpp <span class="special">;</span>
56 Even with this simple setup, you can do some interesting things. First of
57 all, just invoking <span class="command"><strong>b2</strong></span> will build the <code class="filename">hello
58 </code> executable by compiling and linking <code class="filename">hello.cpp
59 </code>. By default, the debug variant is built. Now, to build the release
60 variant of <code class="filename">hello</code>, invoke
68 Note that the debug and release variants are created in different directories,
69 so you can switch between variants or even build multiple variants at
70 once, without any unnecessary recompilation. Let us extend the example by
71 adding another line to our project's <code class="filename">Jamroot</code>:
74 <pre class="programlisting">
75 exe hello2 <span class="special">:</span> hello.cpp <span class="special">;</span>
79 Now let us build both the debug and release variants of our project again:
87 Note that two variants of <code class="filename">hello2</code> are linked. Since we
88 have already built both variants of <code class="filename">hello</code>, hello.cpp
89 will not be recompiled; instead the existing object files will just be
90 linked into the corresponding variants of <code class="filename">hello2</code>. Now
91 let us remove all the built products:
95 b2 --clean debug release
99 It is also possible to build or clean specific targets. The following two
100 commands, respectively, build or clean only the debug version of
101 <code class="filename">hello2</code>.
111 <div class="section">
112 <div class="titlepage"><div><div><h3 class="title">
113 <a name="bbv2.tutorial.properties"></a>Properties</h3></div></div></div>
114 <div class="toc"><dl class="toc">
115 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.properties.requirements">Build Requests and Target Requirements</a></span></dt>
116 <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.properties.project_attributes">Project Attributes</a></span></dt>
119 To represent aspects of target configuration such as
120 debug and release variants, or single- and multi-threaded
121 builds portably, Boost.Build uses <em class="firstterm">features</em> with
122 associated <em class="firstterm">values</em>. For
123 example, the <code class="computeroutput">debug-symbols</code> feature can have a value of <code class="computeroutput">on</code> or
124 <code class="computeroutput">off</code>. A <em class="firstterm">property</em> is just a (feature,
125 value) pair. When a user initiates a build, Boost.Build
126 automatically translates the requested properties into appropriate
127 command-line flags for invoking toolset components like compilers
131 There are many built-in features that can be combined to
132 produce arbitrary build configurations. The following command
133 builds the project's <code class="computeroutput">release</code> variant with inlining
134 disabled and debug symbols enabled:
137 b2 release inlining=off debug-symbols=on
142 Properties on the command-line are specified with the syntax:
146 <em class="replaceable"><code>feature-name</code></em>=<em class="replaceable"><code>feature-value</code></em>
151 The <code class="option">release</code> and <code class="option">debug</code> that we have seen
152 in <span class="command"><strong>b2</strong></span> invocations are just a shorthand way to specify
153 values of the <code class="varname">variant</code> feature. For example, the
154 command above could also have been written this way:
158 b2 variant=release inlining=off debug-symbols=on
163 <code class="varname">variant</code> is so commonly-used that it has been given
164 special status as an <em class="firstterm">implicit</em> feature—
165 Boost.Build will deduce its identity just from the name of one of its
169 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>.
171 <div class="section">
172 <div class="titlepage"><div><div><h4 class="title">
173 <a name="bbv2.tutorial.properties.requirements"></a>Build Requests and Target Requirements</h4></div></div></div>
175 The set of properties specified on the command line constitutes
176 a <em class="firstterm">build request</em>—a description of
177 the desired properties for building the requested targets (or,
178 if no targets were explicitly requested, the project in the
179 current directory). The <span class="emphasis"><em>actual</em></span>
180 properties used for building targets are typically a
181 combination of the build request and properties derived from
182 the project's <code class="filename">Jamroot</code> (and its other
183 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
184 locations of <code class="computeroutput">#include</code>d header files are normally
185 not specified on the command-line, but described in
186 Jamfiles as <em class="firstterm">target
187 requirements</em> and automatically combined with the
188 build request for those targets. Multithread-enabled
189 compilation is another example of a typical target
190 requirement. The Jamfile fragment below
191 illustrates how these requirements might be specified.
193 <pre class="programlisting">
195 <span class="special">:</span> hello.cpp
196 <span class="special">:</span> <include>boost <threading>multi
197 <span class="special">;</span>
200 When <code class="filename">hello</code> is built, the two requirements specified
201 above will always be present. If the build request given on the
202 <span class="command"><strong>b2</strong></span> command-line explictly contradicts a target's
203 requirements, the target requirements usually override (or, in the case
204 of “free”” features like
205 <code class="varname"><include></code>,
206 <a href="#ftn.idp547188496" class="footnote" name="idp547188496"><sup class="footnote">[13]</sup></a>
207 augments) the build request.
209 <div class="tip"><table border="0" summary="Tip">
211 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
212 <th align="left">Tip</th>
214 <tr><td align="left" valign="top"><p>
215 The value of the <code class="varname"><include></code> feature is
216 relative to the location of <code class="filename">Jamroot</code> where it is
221 <div class="section">
222 <div class="titlepage"><div><div><h4 class="title">
223 <a name="bbv2.tutorial.properties.project_attributes"></a>Project Attributes</h4></div></div></div>
225 If we want the same requirements for our other target,
226 <code class="filename">hello2</code>, we could simply duplicate them. However,
227 as projects grow, that approach leads to a great deal of repeated
228 boilerplate in Jamfiles.
230 Fortunately, there's a better way. Each project can specify a set of
231 <em class="firstterm">attributes</em>, including requirements:
234 <pre class="programlisting">
236 <span class="special">:</span> requirements <include>/home/ghost/Work/boost <threading>multi
237 <span class="special">;</span>
239 exe hello <span class="special">:</span> hello.cpp <span class="special">;</span>
240 exe hello2 <span class="special">:</span> hello.cpp <span class="special">;</span></pre>
243 The effect would be as if we specified the same requirement for both
244 <code class="filename">hello</code> and <code class="filename">hello2</code>.
248 <div class="section">
249 <div class="titlepage"><div><div><h3 class="title">
250 <a name="bbv2.tutorial.hierarchy"></a>Project Hierarchies</h3></div></div></div>
252 So far we have only considered examples with one project, with
253 one user-written Boost.Jam file, <code class="filename">Jamroot</code>. A typical
254 large codebase would be composed of many projects organized into a tree.
255 The top of the tree is called the <em class="firstterm">project root</em>.
256 Every subproject is defined by a file called <code class="filename">Jamfile</code>
257 in a descendant directory of the project root. The parent project of a
258 subproject is defined by the nearest <code class="filename">Jamfile</code> or
259 <code class="filename">Jamroot</code> file in an ancestor directory. For example,
260 in the following directory layout:
282 the project root is <code class="filename">top/</code>. The projects in
283 <code class="filename">top/app/</code> and <code class="filename">top/util/foo/</code> are
284 immediate children of the root project.
287 <div class="note"><table border="0" summary="Note">
289 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
290 <th align="left">Note</th>
292 <tr><td align="left" valign="top"><p>
293 When we refer to a “Jamfile,” set in normal
294 type, we mean a file called either
295 <code class="filename">Jamfile</code> or
296 <code class="filename">Jamroot</code>. When we need to be more
297 specific, the filename will be set as
298 “<code class="filename">Jamfile</code>” or
299 “<code class="filename">Jamroot</code>.”
305 Projects inherit all attributes (such as requirements)
306 from their parents. Inherited requirements are combined with
307 any requirements specified by the subproject.
308 For example, if <code class="filename">top/Jamroot</code> has
311 <pre class="programlisting">
312 <include>/home/ghost/local
316 in its requirements, then all of its subprojects will have it
317 in their requirements, too. Of course, any project can add
318 include paths to those specified by its parents. <a href="#ftn.idp547216640" class="footnote" name="idp547216640"><sup class="footnote">[14]</sup></a>
319 More details can be found in
320 <a class="xref" href="overview.html#bbv2.overview.projects" title="Projects">the section called “Projects”</a>.
323 Invoking <span class="command"><strong>b2</strong></span> without explicitly specifying
324 any targets on the command line builds the project rooted in the
325 current directory. Building a project does not automatically
326 cause its subprojects to be built unless the parent project's
327 Jamfile explicitly requests it. In our example,
328 <code class="filename">top/Jamroot</code> might contain:
331 <pre class="programlisting">
332 build-project app <span class="special">;</span>
336 which would cause the project in <code class="filename">top/app/</code>
337 to be built whenever the project in <code class="filename">top/</code> is
338 built. However, targets in <code class="filename">top/util/foo/</code>
339 will be built only if they are needed by targets in
340 <code class="filename">top/</code> or <code class="filename">top/app/</code>.
343 <div class="section">
344 <div class="titlepage"><div><div><h3 class="title">
345 <a name="bbv2.tutorial.libs"></a>Dependent Targets</h3></div></div></div>
347 When building a target <code class="filename">X</code> that depends on first
348 building another target <code class="filename">Y</code> (such as a
349 library that must be linked with <em class="firstterm">X</em>),
350 <code class="filename">Y</code> is called a
351 <em class="firstterm">dependency</em> of <code class="filename">X</code> and
352 <code class="filename">X</code> is termed a
353 <em class="firstterm">dependent</em> of <code class="filename">Y</code>.
355 <p>To get a feeling of target dependencies, let's continue the
356 above example and see how <code class="filename">top/app/Jamfile</code> can
357 use libraries from <code class="filename">top/util/foo</code>. If
358 <code class="filename">top/util/foo/Jamfile</code> contains
361 <pre class="programlisting">
362 lib bar <span class="special">:</span> bar.cpp <span class="special">;</span>
366 then to use this library in <code class="filename">top/app/Jamfile</code>, we can
370 <pre class="programlisting">
371 exe app <span class="special">:</span> app.cpp ../util/foo//bar <span class="special">;</span>
375 While <code class="computeroutput">app.cpp</code> refers to a regular source file,
376 <code class="computeroutput">../util/foo//bar</code> is a reference to another target:
377 a library <code class="filename">bar</code> declared in the Jamfile at
378 <code class="filename">../util/foo</code>.
380 <div class="tip"><table border="0" summary="Tip">
382 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
383 <th align="left">Tip</th>
385 <tr><td align="left" valign="top"><p>Some other build system have special syntax for listing dependent
386 libraries, for example <code class="varname">LIBS</code> variable. In Boost.Build,
387 you just add the library to the list of sources.
390 <p>Suppose we build <code class="filename">app</code> with:
393 b2 app optimization=full define=USE_ASM
396 Which properties will be used to build <code class="computeroutput">foo</code>? The answer is
397 that some features are
398 <em class="firstterm">propagated</em>—Boost.Build attempts to use
399 dependencies with the same value of propagated features. The
400 <code class="varname"><optimization></code> feature is propagated, so both
401 <code class="filename">app</code> and <code class="filename">foo</code> will be compiled
402 with full optimization. But <code class="varname"><define></code> is not
403 propagated: its value will be added as-is to the compiler flags for
404 <code class="filename">a.cpp</code>, but won't affect <code class="filename">foo</code>.
407 Let's improve this project further. The library probably has some headers
408 that must be used when compiling <code class="filename">app.cpp</code>. We could
409 manually add the necessary <code class="computeroutput">#include</code> paths to
410 <code class="filename">app</code>'s requirements as values of the
411 <code class="varname"><include> </code> feature, but then this work will be
412 repeated for all programs that use <code class="filename">foo</code>. A better
413 solution is to modify <code class="filename">util/foo/Jamfile</code> in this way:
416 <pre class="programlisting">
418 <span class="special">:</span> usage-requirements <include>.
419 <span class="special">;</span>
421 lib foo <span class="special">:</span> foo.cpp <span class="special">;</span></pre>
424 Usage requirements are applied not to the target being declared but to its
425 dependants. In this case, <code class="literal"><include>.</code> will be
426 applied to all targets that directly depend on <code class="filename">foo</code>.
429 Another improvement is using symbolic identifiers to refer to the library,
430 as opposed to <code class="filename">Jamfile</code> location. In a large project, a
431 library can be used by many targets, and if they all use <code class="filename">Jamfile
432 </code> location, a change in directory organization entails much
433 work. The solution is to use project ids—symbolic names not tied to
434 directory layout. First, we need to assign a project id by adding this
435 code to <code class="filename">Jamroot</code>:
437 <pre class="programlisting">
438 use-project /library-example/foo <span class="special">:</span> util/foo <span class="special">;</span></pre>
440 Second, we modify <code class="filename">app/Jamfile</code> to use the project id:
442 <pre class="programlisting">
443 exe app : app.cpp /library-example/foo//bar ;</pre>
446 The <code class="filename">/library-example/foo//bar</code> syntax is used to refer
447 to the target <code class="filename">bar</code> in the project with id <code class="filename">
448 /library-example/foo</code>. We've achieved our goal—if the
449 library is moved to a different directory, only <code class="filename">Jamroot
450 </code> must be modified. Note that project ids are global—two
451 Jamfiles are not allowed to assign the same project id to different
454 <div class="tip"><table border="0" summary="Tip">
456 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
457 <th align="left">Tip</th>
459 <tr><td align="left" valign="top">
460 <p>If you want all applications in some project to link to a certain
461 library, you can avoid having to specify it directly the sources of
462 every target by using the <code class="varname"><library></code> property.
463 For example, if <code class="filename">/boost/filesystem//fs</code> should be
464 linked to all applications in your project, you can add
465 <code class="computeroutput"><library>/boost/filesystem//fs</code> to the project's
466 requirements, like this:
468 <pre class="programlisting">
470 <span class="special">:</span> requirements <library>/boost/filesystem//fs
471 <span class="special">;</span></pre>
475 <div class="section">
476 <div class="titlepage"><div><div><h3 class="title">
477 <a name="bbv2.tutorial.linkage"></a>Static and shared libaries</h3></div></div></div>
479 Libraries can be either <span class="emphasis"><em>static</em></span>, which means they are
480 included in executable files that use them, or <span class="emphasis"><em>shared</em></span>
481 (a.k.a. <span class="emphasis"><em>dynamic</em></span>), which are only referred to from
482 executables, and must be available at run time. Boost.Build can create and
486 The kind of library produced from a <code class="computeroutput">lib</code> target is determined
487 by the value of the <code class="varname">link</code> feature. Default value is
488 <code class="literal">shared</code>, and to build a static library, the value should
489 be <code class="literal">static</code>. You can request a static build either on the
492 <pre class="programlisting">b2 link=static</pre>
494 or in the library's requirements:
496 <pre class="programlisting">lib l <span class="special">:</span> l.cpp <span class="special">:</span> <link>static <span class="special">;</span></pre>
500 We can also use the <code class="varname"><link></code> property to express
501 linking requirements on a per-target basis. For example, if a particular
502 executable can be correctly built only with the static version of a
503 library, we can qualify the executable's <a class="link" href="reference.html#bbv2.reference.targets.references">target reference</a> to the
509 <pre class="programlisting">
510 exe important <span class="special">:</span> main.cpp helpers/<link>static <span class="special">;</span></pre>
513 No matter what arguments are specified on the <span class="command"><strong>b2</strong></span>
514 command line, <code class="filename">important</code> will only be linked with the
515 static version of <code class="filename">helpers</code>.
518 Specifying properties in target references is especially useful if you use
519 a library defined in some other project (one you can't change) but you
520 still want static (or dynamic) linking to that library in all cases. If
521 that library is used by many targets, you <span class="emphasis"><em>could</em></span> use
522 target references everywhere:
525 <pre class="programlisting">
526 exe e1 <span class="special">:</span> e1.cpp /other_project//bar/<link>static <span class="special">;</span>
527 exe e10 <span class="special">:</span> e10.cpp /other_project//bar/<link>static <span class="special">;</span></pre>
530 but that's far from being convenient. A better approach is to introduce a
531 level of indirection. Create a local <span class="type">alias</span> target that refers
532 to the static (or dynamic) version of <code class="filename">foo</code>:
535 <pre class="programlisting">
536 alias foo : /other_project//bar/<link>static ;
537 exe e1 : e1.cpp foo ;
538 exe e10 : e10.cpp foo ;</pre>
541 The <a class="link" href="tasks.html#bbv2.tasks.alias" title="Alias">alias</a> rule is specifically
542 used to rename a reference to a target and possibly change the
547 <div class="tip"><table border="0" summary="Tip">
549 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Tip]" src="../../../doc/src/images/tip.png"></td>
550 <th align="left">Tip</th>
552 <tr><td align="left" valign="top">
554 When one library uses another, you put the second library in the source
555 list of the first. For example:
557 <pre class="programlisting">
558 lib utils <span class="special">:</span> utils.cpp /boost/filesystem//fs <span class="special">;</span>
559 lib core <span class="special">:</span> core.cpp utils <span class="special">;</span>
560 exe app <span class="special">:</span> app.cpp core <span class="special">;</span></pre>
562 This works no matter what kind of linking is used. When <code class="filename">core
563 </code> is built as a shared library, it is linked directly into
564 <code class="filename">utils</code>. Static libraries can't link to other
565 libraries, so when <code class="filename">core</code> is built as a static
566 library, its dependency on <code class="filename">utils</code> is passed along to
567 <code class="filename">core</code>'s dependents, causing <code class="filename">app</code>
568 to be linked with both <code class="filename">core</code> and <code class="filename">utils
573 <div class="note"><table border="0" summary="Note">
575 <td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../doc/src/images/note.png"></td>
576 <th align="left">Note</th>
578 <tr><td align="left" valign="top"><p>
579 (Note for non-UNIX system). Typically, shared libraries must be
580 installed to a directory in the dynamic linker's search path. Otherwise,
581 applications that use shared libraries can't be started. On Windows, the
582 dynamic linker's search path is given by the <code class="envar">PATH</code>
583 environment variable. This restriction is lifted when you use
584 Boost.Build testing facilities—the <code class="envar">PATH</code> variable
585 will be automatically adjusted before running the executable.
590 <div class="section">
591 <div class="titlepage"><div><div><h3 class="title">
592 <a name="bbv2.tutorial.conditions"></a>Conditions and alternatives</h3></div></div></div>
594 Sometimes, particular relationships need to be maintained among a target's
595 build properties. For example, you might want to set specific <code class="computeroutput">
596 #define</code> when a library is built as shared, or when a target's
597 <code class="computeroutput">release</code> variant is built. This can be achieved using
598 <em class="firstterm">conditional requirements</em>.
601 <pre class="programlisting">
602 lib network <span class="special">:</span> network.cpp
603 <span class="special">:</span> <span class="bold"><strong><link>shared:<define>NETWORK_LIB_SHARED</strong></span>
604 <variant>release:<define>EXTRA_FAST
605 <span class="special">;</span></pre>
608 In the example above, whenever <code class="filename">network</code> is built with
609 <code class="computeroutput"><link>shared</code>, <code class="computeroutput"><define>NETWORK_LIB_SHARED
610 </code> will be in its properties, too. Also, whenever its release variant
611 is built, <code class="computeroutput"><define>EXTRA_FAST</code> will appear in its
615 Sometimes the ways a target is built are so different that describing them
616 using conditional requirements would be hard. For example, imagine that a
617 library actually uses different source files depending on the toolset used
618 to build it. We can express this situation using <em class="firstterm">target
621 <pre class="programlisting">
622 lib demangler <span class="special">:</span> dummy_demangler.cpp <span class="special">;</span> <span class="comment"># alternative 1</span>
623 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>
624 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>
626 When building <code class="filename">demangler</code>, Boost.Build will compare
627 requirements for each alternative with build properties to find the best
628 match. For example, when building with <code class="computeroutput"><toolset>gcc</code>
629 alternative 2, will be selected, and when building with
630 <code class="computeroutput"><toolset>msvc</code> alternative 3 will be selected. In all
631 other cases, the most generic alternative 1 will be built.
634 <div class="section">
635 <div class="titlepage"><div><div><h3 class="title">
636 <a name="bbv2.tutorial.prebuilt"></a>Prebuilt targets</h3></div></div></div>
638 To link to libraries whose build instructions aren't given in a Jamfile,
639 you need to create <code class="computeroutput">lib</code> targets with an appropriate
640 <code class="varname">file</code> property. Target alternatives can be used to
641 associate multiple library files with a single conceptual target. For
644 <pre class="programlisting">
645 <span class="comment"># util/lib2/Jamfile</span>
647 <span class="special">:</span>
648 <span class="special">:</span> <file>lib2_release.a <variant>release
649 <span class="special">;</span>
652 <span class="special">:</span>
653 <span class="special">:</span> <file>lib2_debug.a <variant>debug
654 <span class="special">;</span></pre>
657 This example defines two alternatives for <code class="filename">lib2</code>, and
658 for each one names a prebuilt file. Naturally, there are no sources.
659 Instead, the <code class="varname"><file></code> feature is used to specify
663 Once a prebuilt target has been declared, it can be used just like any
667 <pre class="programlisting">
668 exe app <span class="special">:</span> app.cpp ../util/lib2//lib2 <span class="special">;</span></pre>
671 As with any target, the alternative selected depends on the properties
672 propagated from <code class="filename">lib2</code>'s dependants. If we build the
673 release and debug versions of <code class="filename">app</code> will be linked
674 with <code class="filename">lib2_release.a</code> and <code class="filename">lib2_debug.a
675 </code>, respectively.
678 System libraries—those that are automatically found by the toolset
679 by searching through some set of predetermined paths—should be
680 declared almost like regular ones:
683 <pre class="programlisting">
684 lib pythonlib <span class="special">:</span> <span class="special">:</span> <name>python22 <span class="special">;</span></pre>
687 We again don't specify any sources, but give a <code class="varname">name</code>
688 that should be passed to the compiler. If the gcc toolset were used to
689 link an executable target to <code class="filename">pythonlib</code>,
690 <code class="option">-lpython22</code> would appear in the command line (other
691 compilers may use different options).
694 We can also specify where the toolset should look for the library:
697 <pre class="programlisting">
698 lib pythonlib <span class="special">:</span> <span class="special">:</span> <name>python22 <search>/opt/lib <span class="special">;</span></pre>
701 And, of course, target alternatives can be used in the usual way:
704 <pre class="programlisting">
705 lib pythonlib <span class="special">:</span> <span class="special">:</span> <name>python22 <variant>release <span class="special">;</span>
706 lib pythonlib <span class="special">:</span> <span class="special">:</span> <name>python22_d <variant>debug <span class="special">;</span></pre>
710 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>.
713 <div class="footnotes">
714 <br><hr style="width:100; text-align:left;margin-left: 0">
715 <div id="ftn.idp547188496" class="footnote"><p><a href="#idp547188496" class="para"><sup class="para">[13] </sup></a>
716 See <a class="xref" href="reference.html#bbv2.reference.features.attributes" title="Feature Attributes">the section called “Feature Attributes”</a>
718 <div id="ftn.idp547216640" class="footnote"><p><a href="#idp547216640" class="para"><sup class="para">[14] </sup></a>Many
719 features will be overridden,
720 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
721 information</p></div>
724 <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
725 <td align="left"></td>
726 <td align="right"><div class="copyright-footer">Copyright © 2006-2009, 2014 Vladimir Prus<p>Distributed under the Boost Software License, Version 1.0.
727 (See accompanying file <code class="filename">LICENSE_1_0.txt</code> or copy at
728 <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a>)
733 <div class="spirit-nav">
734 <a accesskey="p" href="installation.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>