tutorial.html 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <html>
  2. <head>
  3. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  4. <title>Chapter 23. Tutorial</title>
  5. <link rel="stylesheet" href="../boostbook.css" type="text/css">
  6. <meta name="generator" content="DocBook XSL Stylesheets V1.68.1">
  7. <style type="text/css">
  8. body { background-image: url('http://docbook.sourceforge.net/release/images/draft.png');
  9. background-repeat: no-repeat;
  10. background-position: top left;
  11. /* The following properties make the watermark "fixed" on the page. */
  12. /* I think that's just a bit too distracting for the reader... */
  13. /* background-attachment: fixed; */
  14. /* background-position: center center; */
  15. }</style>
  16. <link rel="start" href="../index.html" title="The Boost C++ Libraries">
  17. <link rel="up" href="../bbv2.html" title="Part III. Boost.Build v2 User Manual">
  18. <link rel="prev" href="installation.html" title="Chapter 22. Installation">
  19. <link rel="next" href="tutorial/properties.html" title="Properties">
  20. </head>
  21. <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
  22. <table cellpadding="2" width="100%">
  23. <td valign="top"><img alt="boost.png (6897 bytes)" width="277" height="86" src="../../../boost.png"></td>
  24. <td align="center"><a href="../../../index.htm">Home</a></td>
  25. <td align="center"><a href="../../../libs/libraries.htm">Libraries</a></td>
  26. <td align="center"><a href="../../../people/people.htm">People</a></td>
  27. <td align="center"><a href="../../../more/faq.htm">FAQ</a></td>
  28. <td align="center"><a href="../../../more/index.htm">More</a></td>
  29. </table>
  30. <hr>
  31. <div class="spirit-nav">
  32. <a accesskey="p" href="installation.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../bbv2.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="tutorial/properties.html"><img src="../images/next.png" alt="Next"></a>
  33. </div>
  34. <div class="chapter" lang="en">
  35. <div class="titlepage"><div><div><h2 class="title">
  36. <a name="bbv2.tutorial"></a>Chapter 23. Tutorial</h2></div></div></div>
  37. <div class="toc">
  38. <p><b>Table of Contents</b></p>
  39. <dl>
  40. <dt><span class="section"><a href="tutorial.html#bbv2.tutorial.hello">Hello, world</a></span></dt>
  41. <dt><span class="section"><a href="tutorial/properties.html">Properties</a></span></dt>
  42. <dd><dl>
  43. <dt><span class="section"><a href="tutorial/properties.html#bbv2.tutorial.properties.requirements">Build Requests and Target Requirements</a></span></dt>
  44. <dt><span class="section"><a href="tutorial/properties.html#bbv2.tutorial.properties.project_attributes">Project Attributes</a></span></dt>
  45. </dl></dd>
  46. <dt><span class="section"><a href="tutorial/hierarchy.html">Project Hierarchies</a></span></dt>
  47. <dt><span class="section"><a href="tutorial/libs.html">Dependent Targets</a></span></dt>
  48. <dt><span class="section"><a href="tutorial/linkage.html">Static and shared libaries</a></span></dt>
  49. <dt><span class="section"><a href="tutorial/conditions.html">Conditions and alternatives</a></span></dt>
  50. <dt><span class="section"><a href="tutorial/prebuilt.html">Prebuilt targets</a></span></dt>
  51. </dl>
  52. </div>
  53. <div class="section" lang="en">
  54. <div class="titlepage"><div><div><h2 class="title" style="clear: both">
  55. <a name="bbv2.tutorial.hello"></a>Hello, world</h2></div></div></div>
  56. <p>The simplest project that Boost.Build can construct is
  57. stored in <code class="filename">example/hello/</code> directory. The
  58. project is described by a file
  59. called <code class="filename">Jamroot</code> that contains:
  60. </p>
  61. <pre class="programlisting">
  62. exe hello : hello.cpp ;
  63. </pre>
  64. <p>
  65. Even with this simple setup, you can do some interesting
  66. things. First of all, just invoking <span><strong class="command">bjam</strong></span> will
  67. build the <code class="filename">hello</code>
  68. executable by compiling and
  69. linking <code class="filename">hello.cpp</code>. By default, debug variant
  70. is built. Now, to build the
  71. release variant of <code class="filename">hello</code>, invoke
  72. </p>
  73. <pre class="screen">
  74. bjam release
  75. </pre>
  76. <p>
  77. Note that debug and release variants are created in different
  78. directories, so you can switch between variants or even build
  79. multiple variants at once, without any unnecessary
  80. recompilation. Let's extend the example by adding another line
  81. to our project's <code class="filename">Jamroot</code>:
  82. </p>
  83. <pre class="programlisting">
  84. exe hello2 : hello.cpp ;
  85. </pre>
  86. <p>
  87. Now let us build both the debug and release variants of our project
  88. again:
  89. </p>
  90. <pre class="screen">
  91. bjam debug release
  92. </pre>
  93. <p>
  94. Note that two variants of <code class="filename">hello2</code> are linked.
  95. Since we have already built both variants
  96. of <code class="filename">hello</code>, hello.cpp won't be recompiled;
  97. instead the existing object files will just be linked into the
  98. corresponding variants of <code class="filename">hello2</code>. Now
  99. let's remove all the built products:
  100. </p>
  101. <pre class="screen">
  102. bjam --clean debug release
  103. </pre>
  104. <p>
  105. It's also possible to build or clean specific targets. The
  106. following two commands, respectively, build or clean only the
  107. debug version of <code class="filename">hello2</code>.
  108. </p>
  109. <pre class="screen">
  110. bjam hello2
  111. bjam --clean hello2
  112. </pre>
  113. </div>
  114. </div>
  115. <table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
  116. <td align="left"></td>
  117. <td align="right"><small></small></td>
  118. </tr></table>
  119. <hr>
  120. <div class="spirit-nav">
  121. <a accesskey="p" href="installation.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../bbv2.html"><img src="../images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../images/home.png" alt="Home"></a><a accesskey="n" href="tutorial/properties.html"><img src="../images/next.png" alt="Next"></a>
  122. </div>
  123. </body>
  124. </html>
粤ICP备19079148号