1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Building Hello World</title> 5<link rel="stylesheet" href="../../boostbook.css" type="text/css"> 6<meta name="generator" content="DocBook XSL Stylesheets V1.79.1"> 7<link rel="home" href="../index.html" title="Boost.Python Tutorial"> 8<link rel="up" href="../index.html" title="Boost.Python Tutorial"> 9<link rel="prev" href="../index.html" title="Boost.Python Tutorial"> 10<link rel="next" href="exposing.html" title="Exposing Classes"> 11</head> 12<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF"> 13<table cellpadding="2" width="100%"><tr><td valign="top"><img alt="" width="" height="" src="../../images/boost.png"></td></tr></table> 14<hr> 15<div class="spirit-nav"> 16<a accesskey="p" href="../index.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="exposing.html"><img src="../../images/next.png" alt="Next"></a> 17</div> 18<div class="section"> 19<div class="titlepage"><div><div><h2 class="title" style="clear: both"> 20<a name="tutorial.hello"></a><a class="link" href="hello.html" title="Building Hello World">Building Hello World</a> 21</h2></div></div></div> 22<h3> 23<a name="tutorial.hello.h0"></a> 24 <span class="phrase"><a name="tutorial.hello.from_start_to_finish"></a></span><a class="link" href="hello.html#tutorial.hello.from_start_to_finish">From 25 Start To Finish</a> 26 </h3> 27<p> 28 Now the first thing you'd want to do is to build the Hello World module and 29 try it for yourself in Python. In this section, we will outline the steps necessary 30 to achieve that. We will use the build tool that comes bundled with every boost 31 distribution: <span class="bold"><strong>bjam</strong></span>. 32 </p> 33<div class="note"><table border="0" summary="Note"> 34<tr> 35<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../images/note.png"></td> 36<th align="left">Note</th> 37</tr> 38<tr><td align="left" valign="top"> 39<p> 40 <span class="bold"><strong>Building without bjam</strong></span> 41 </p> 42<p> 43 Besides bjam, there are of course other ways to get your module built. What's 44 written here should not be taken as "the one and only way". There 45 are of course other build tools apart from <code class="literal">bjam</code>. 46 </p> 47<p> 48 Take note however that the preferred build tool for Boost.Python is bjam. 49 There are so many ways to set up the build incorrectly. Experience shows 50 that 90% of the "I can't build Boost.Python" problems come from 51 people who had to use a different tool. 52 </p> 53</td></tr> 54</table></div> 55<p> 56 We will skip over the details. Our objective will be to simply create the hello 57 world module and run it in Python. For a complete reference to building Boost.Python, 58 check out: <a href="../../building.html" target="_top">building.html</a>. After this 59 brief <span class="emphasis"><em>bjam</em></span> tutorial, we should have built the DLLs and 60 run a python program using the extension. 61 </p> 62<p> 63 The tutorial example can be found in the directory: <code class="literal">libs/python/example/tutorial</code>. 64 There, you can find: 65 </p> 66<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 67<li class="listitem"> 68 hello.cpp 69 </li> 70<li class="listitem"> 71 hello.py 72 </li> 73<li class="listitem"> 74 Jamroot 75 </li> 76</ul></div> 77<p> 78 The <code class="literal">hello.cpp</code> file is our C++ hello world example. The 79 <code class="literal">Jamroot</code> is a minimalist <span class="emphasis"><em>bjam</em></span> script 80 that builds the DLLs for us. Finally, <code class="literal">hello.py</code> is our Python 81 program that uses the extension in <code class="literal">hello.cpp</code>. 82 </p> 83<p> 84 Before anything else, you should have the bjam executable in your boost directory 85 or somewhere in your path such that <code class="literal">bjam</code> can be executed 86 in the command line. Pre-built Boost.Jam executables are available for most 87 platforms. The complete list of Bjam executables can be found <a href="http://sourceforge.net/project/showfiles.php?group_id=7586" target="_top">here</a>. 88 </p> 89<h3> 90<a name="tutorial.hello.h1"></a> 91 <span class="phrase"><a name="tutorial.hello.let_s_jam"></a></span><a class="link" href="hello.html#tutorial.hello.let_s_jam">Let's 92 Jam!</a> 93 </h3> 94<p> 95 <span class="inlinemediaobject"><img src="../../images/jam.png"></span> 96 </p> 97<p> 98 <a href="../../../../../example/tutorial/Jamroot" target="_top">Here</a> is our minimalist 99 Jamroot file. Simply copy the file and tweak <code class="literal">use-project boost</code> 100 to where your boost root directory is and you're OK. 101 </p> 102<p> 103 The comments contained in the Jamroot file above should be sufficient to get 104 you going. 105 </p> 106<h3> 107<a name="tutorial.hello.h2"></a> 108 <span class="phrase"><a name="tutorial.hello.running_bjam"></a></span><a class="link" href="hello.html#tutorial.hello.running_bjam">Running 109 bjam</a> 110 </h3> 111<p> 112 <span class="emphasis"><em>bjam</em></span> is run using your operating system's command line 113 interpreter. 114 </p> 115<div class="blockquote"><blockquote class="blockquote"><p> 116 Start it up. 117 </p></blockquote></div> 118<p> 119 A file called user-config.jam in your home directory is used to configure your 120 tools. In Windows, your home directory can be found by typing: 121 </p> 122<pre class="programlisting">ECHO %HOMEDRIVE%%HOMEPATH% 123</pre> 124<p> 125 into a command prompt window. Your file should at least have the rules for 126 your compiler and your python installation. A specific example of this on Windows 127 would be: 128 </p> 129<pre class="programlisting"># MSVC configuration 130using msvc : 8.0 ; 131 132# Python configuration 133using python : 2.4 : C:<span class="emphasis"><em>dev/tools/Python</em></span> ; 134</pre> 135<p> 136 The first rule tells Bjam to use the MSVC 8.0 compiler and associated tools. 137 The second rule provides information on Python, its version and where it is 138 located. The above assumes that the Python installation is in <code class="literal">C:<span class="emphasis"><em>dev/tools\/Python</em></span></code>. 139 If you have one fairly "standard" python installation for your platform, 140 you might not need to do this. 141 </p> 142<p> 143 Now we are ready... Be sure to <code class="literal">cd</code> to <code class="literal">libs/python/example/tutorial</code> 144 where the tutorial <code class="literal">"hello.cpp"</code> and the <code class="literal">"Jamroot"</code> 145 is situated. 146 </p> 147<p> 148 Finally: 149 </p> 150<pre class="programlisting"><span class="identifier">bjam</span> 151</pre> 152<p> 153 It should be building now: 154 </p> 155<pre class="programlisting">cd C:\dev\boost\libs\python\example\tutorial 156bjam 157...patience... 158...found 1101 targets... 159...updating 35 targets... 160</pre> 161<p> 162 And so on... Finally: 163 </p> 164<pre class="programlisting"> Creating library <span class="emphasis"><em>path-to-boost_python.dll</em></span> 165 Creating library /path-to-hello_ext.exp/ 166**passed** ... hello.test 167...updated 35 targets... 168</pre> 169<p> 170 Or something similar. If all is well, you should now have built the DLLs and 171 run the Python program. 172 </p> 173<div class="blockquote"><blockquote class="blockquote"><p> 174 <span class="bold"><strong>There you go... Have fun!</strong></span> 175 </p></blockquote></div> 176</div> 177<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 178<td align="left"></td> 179<td align="right"><div class="copyright-footer">Copyright © 2002-2005 Joel 180 de Guzman, David Abrahams<p> 181 Distributed under the Boost Software License, Version 1.0. (See accompanying 182 file LICENSE_1_0.txt or copy at <a href="http://www.boost.org/LICENSE_1_0.txt" target="_top">http://www.boost.org/LICENSE_1_0.txt</a> 183 </p> 184</div></td> 185</tr></table> 186<hr> 187<div class="spirit-nav"> 188<a accesskey="p" href="../index.html"><img src="../../images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.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="exposing.html"><img src="../../images/next.png" alt="Next"></a> 189</div> 190</body> 191</html> 192