mirror of
https://github.com/boostorg/python.git
synced 2026-01-20 04:42:28 +00:00
219 lines
9.2 KiB
HTML
219 lines
9.2 KiB
HTML
<html>
|
||
<head>
|
||
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
|
||
<title> Building Hello World</title>
|
||
<link rel="stylesheet" href="../../../../../../../doc/html/boostbook.css" type="text/css">
|
||
<meta name="generator" content="DocBook XSL Stylesheets V1.66.1">
|
||
<link rel="start" href="../index.html" title="Chapter 1. python 1.0">
|
||
<link rel="up" href="../index.html" title="Chapter 1. python 1.0">
|
||
<link rel="prev" href="../index.html" title="Chapter 1. python 1.0">
|
||
<link rel="next" href="exposing.html" title=" Exposing Classes">
|
||
</head>
|
||
<body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
|
||
<table cellpadding="2" width="100%"><tr>
|
||
<td valign="top"><img alt="Boost C++ Libraries" width="277" height="86" src="../../../../../../../boost.png"></td>
|
||
<td align="center"><a href="../../../../../../../index.html">Home</a></td>
|
||
<td align="center"><a href="../../../../../../../libs/libraries.htm">Libraries</a></td>
|
||
<td align="center"><a href="http://www.boost.org/users/people.html">People</a></td>
|
||
<td align="center"><a href="http://www.boost.org/users/faq.html">FAQ</a></td>
|
||
<td align="center"><a href="../../../../../../../more/index.htm">More</a></td>
|
||
</tr></table>
|
||
<hr>
|
||
<div class="spirit-nav">
|
||
<a accesskey="p" href="../index.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="exposing.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
|
||
</div>
|
||
<div class="section" lang="en">
|
||
<div class="titlepage"><div><div><h2 class="title" style="clear: both">
|
||
<a name="python.hello"></a> Building Hello World</h2></div></div></div>
|
||
<a name="hello.from_start_to_finish"></a><h2>
|
||
<a name="id388718"></a>
|
||
From Start To Finish
|
||
</h2>
|
||
<p>
|
||
Now the first thing you'd want to do is to build the Hello World module and
|
||
try it for yourself in Python. In this section, we will outline the steps necessary
|
||
to achieve that. We will use the build tool that comes bundled with every boost
|
||
distribution: <span class="bold"><b>bjam</b></span>.
|
||
</p>
|
||
<div class="note"><table border="0" summary="Note">
|
||
<tr>
|
||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/html/images/note.png"></td>
|
||
<th align="left">Note</th>
|
||
</tr>
|
||
<tr><td colspan="2" align="left" valign="top">
|
||
<p>
|
||
<span class="bold"><b>Building without bjam</b></span>
|
||
</p>
|
||
<p>
|
||
Besides bjam, there are of course other ways to get your module built. What's
|
||
written here should not be taken as "the one and only way". There
|
||
are of course other build tools apart from <tt class="literal">bjam</tt>.
|
||
</p>
|
||
<p>
|
||
Take note however that the preferred build tool for Boost.Python is bjam.
|
||
There are so many ways to set up the build incorrectly. Experience shows
|
||
that 90% of the "I can't build Boost.Python" problems come from
|
||
people who had to use a different tool.
|
||
</p>
|
||
</td></tr>
|
||
</table></div>
|
||
<p>
|
||
We will skip over the details. Our objective will be to simply create the hello
|
||
world module and run it in Python. For a complete reference to building Boost.Python,
|
||
check out: <a href="../../../../building.html" target="_top">building.html</a>. After
|
||
this brief <span class="emphasis"><em>bjam</em></span> tutorial, we should have built the DLLs
|
||
and run a python program using the extension.
|
||
</p>
|
||
<p>
|
||
The tutorial example can be found in the directory: <tt class="literal">libs/python/example/tutorial</tt>.
|
||
There, you can find:
|
||
</p>
|
||
<div class="itemizedlist"><ul type="disc">
|
||
<li>
|
||
hello.cpp
|
||
</li>
|
||
<li>
|
||
hello.py
|
||
</li>
|
||
<li>
|
||
Jamroot
|
||
</li>
|
||
</ul></div>
|
||
<p>
|
||
The <tt class="literal">hello.cpp</tt> file is our C++ hello world example. The
|
||
<tt class="literal">Jamroot</tt> is a minimalist <span class="emphasis"><em>bjam</em></span> script
|
||
that builds the DLLs for us. Finally, <tt class="literal">hello.py</tt> is our Python
|
||
program that uses the extension in <tt class="literal">hello.cpp</tt>.
|
||
</p>
|
||
<p>
|
||
Before anything else, you should have the bjam executable in your boost directory
|
||
or somewhere in your path such that <tt class="literal">bjam</tt> can be executed
|
||
in the command line. Pre-built Boost.Jam executables are available for most
|
||
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>.
|
||
</p>
|
||
<a name="hello.let_s_jam_"></a><h2>
|
||
<a name="id387300"></a>
|
||
Let's Jam!
|
||
</h2>
|
||
<p>
|
||
<span class="inlinemediaobject"><img src="../images/jam.png" alt="jam"></span>
|
||
</p>
|
||
<p>
|
||
<a href="../../../../../example/tutorial/Jamroot" target="_top">Here</a> is our minimalist
|
||
Jamroot file. Simply copy the file and tweak <tt class="literal">use-project boost</tt>
|
||
to where your boost root directory is and your OK.
|
||
</p>
|
||
<p>
|
||
The comments contained in the Jamrules file above should be sufficient to get
|
||
you going.
|
||
</p>
|
||
<a name="hello.running_bjam"></a><h2>
|
||
<a name="id387357"></a>
|
||
Running bjam
|
||
</h2>
|
||
<p>
|
||
<span class="emphasis"><em>bjam</em></span> is run using your operating system's command line
|
||
interpreter.
|
||
</p>
|
||
<div class="blockquote"><blockquote class="blockquote">
|
||
<p>
|
||
</p>
|
||
<p>
|
||
Start it up.
|
||
</p>
|
||
<p>
|
||
</p>
|
||
</blockquote></div>
|
||
<p>
|
||
A file called user-config.jam in your home directory is used to configure your
|
||
tools. In Windows, your home directory can be found by typing:
|
||
</p>
|
||
<pre class="programlisting">ECHO %HOMEDRIVE%%HOMEPATH%
|
||
</pre>
|
||
<p>
|
||
into a command prompt window. Your file should at least have the rules for
|
||
your compiler and your python installation. A specific example of this on Windows
|
||
would be:
|
||
</p>
|
||
<pre class="programlisting"># MSVC configuration
|
||
using msvc : 8.0 ;
|
||
|
||
# Python configuration
|
||
using python : 2.4 : C:/dev/tools<span class="emphasis"><em>Python</em></span> ;
|
||
</pre>
|
||
<p>
|
||
The first rule tells Bjam to use the MSVC 8.0 compiler and associated tools.
|
||
The second rule provides information on Python, its version and where it is
|
||
located. The above assumes that the Python installation is in <tt class="literal">C:/dev/tools/Python/</tt>.
|
||
If you have one fairly "standard" python installation for your platform,
|
||
you might not need to do this.
|
||
</p>
|
||
<p>
|
||
Now we are ready... Be sure to <tt class="literal">cd</tt> to <tt class="literal">libs/python/example/tutorial</tt>
|
||
where the tutorial <tt class="literal">"hello.cpp"</tt> and the <tt class="literal">"Jamroot"</tt>
|
||
is situated.
|
||
</p>
|
||
<p>
|
||
Finally:
|
||
</p>
|
||
<pre class="programlisting"><span class="identifier">bjam</span>
|
||
</pre>
|
||
<p>
|
||
It should be building now:
|
||
</p>
|
||
<pre class="programlisting">cd C:\dev\boost\libs\python\example\tutorial
|
||
bjam
|
||
...patience...
|
||
...found 1101 targets...
|
||
...updating 35 targets...
|
||
</pre>
|
||
<p>
|
||
And so on... Finally:
|
||
</p>
|
||
<pre class="programlisting">Creating library <span class="emphasis"><em>path-to-boost_python.dll</em></span>
|
||
Creating library <span class="emphasis"><em>path-to-'''hello_ext'''.exp</em></span>
|
||
**passed** ... hello.test
|
||
...updated 35 targets...
|
||
</pre>
|
||
<p>
|
||
Or something similar. If all is well, you should now have built the DLLs and
|
||
run the Python program.
|
||
</p>
|
||
<div class="note"><table border="0" summary="Note">
|
||
<tr>
|
||
<td rowspan="2" align="center" valign="top" width="25"><img alt="[Note]" src="../../../../../../../doc/html/images/note.png"></td>
|
||
<th align="left">Note</th>
|
||
</tr>
|
||
<tr><td colspan="2" align="left" valign="top"><p>
|
||
Starting from Boost 1.35, bjam erases the generated executables (e.g. pyd
|
||
file) after the test has concluded to conserve disk space. To keep bjam from
|
||
doing that, pass --preserve-test-targets to bjam.
|
||
</p></td></tr>
|
||
</table></div>
|
||
<div class="blockquote"><blockquote class="blockquote">
|
||
<p>
|
||
</p>
|
||
<p>
|
||
<span class="bold"><b>There you go... Have fun!</b></span>
|
||
</p>
|
||
<p>
|
||
</p>
|
||
</blockquote></div>
|
||
</div>
|
||
<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr>
|
||
<td align="left"></td>
|
||
<td align="right"><div class="copyright-footer">Copyright © 2002-2005 Joel
|
||
de Guzman, David Abrahams<p>
|
||
Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||
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>)
|
||
</p>
|
||
</div></td>
|
||
</tr></table>
|
||
<hr>
|
||
<div class="spirit-nav">
|
||
<a accesskey="p" href="../index.html"><img src="../../../../../../../doc/html/images/prev.png" alt="Prev"></a><a accesskey="u" href="../index.html"><img src="../../../../../../../doc/html/images/up.png" alt="Up"></a><a accesskey="h" href="../index.html"><img src="../../../../../../../doc/html/images/home.png" alt="Home"></a><a accesskey="n" href="exposing.html"><img src="../../../../../../../doc/html/images/next.png" alt="Next"></a>
|
||
</div>
|
||
</body>
|
||
</html>
|