1<html> 2<head> 3<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4<title>Background</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"> 8<link rel="up" href="../building.html" title="Chapter 2. Building and Testing"> 9<link rel="prev" href="../building.html" title="Chapter 2. Building and Testing"> 10<link rel="next" href="no_install_quickstart.html" title="No-Install Quickstart"> 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="../building.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.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="no_install_quickstart.html"><img src="../images/next.png" alt="Next"></a> 17</div> 18<div class="section"> 19<div class="titlepage"><div><div><h3 class="title"> 20<a name="building.background"></a><a class="link" href="background.html" title="Background">Background</a> 21</h3></div></div></div> 22<p> 23 There are two basic models for combining C++ and Python: 24 </p> 25<div class="itemizedlist"><ul class="itemizedlist" style="list-style-type: disc; "> 26<li class="listitem"> 27 <a href="http://www.python.org/doc/current/ext/intro.html" target="_top">extending</a>, 28 in which the end-user launches the Python interpreter executable and 29 imports Python “extension modules” written in C++. Think of taking 30 a library written in C++ and giving it a Python interface so Python programmers 31 can use it. From Python, these modules look just like regular Python 32 modules. 33 </li> 34<li class="listitem"> 35 <a href="http://www.python.org/doc/current/ext/embedding.html" target="_top">embedding</a>, 36 in which the end-user launches a program written in C++ that in turn 37 invokes the Python interpreter as a library subroutine. Think of adding 38 scriptability to an existing application. 39 </li> 40</ul></div> 41<p> 42 The key distinction between extending and embedding is the location of the 43 C++ <code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code> 44 function: in the Python interpreter executable, or in some other program, 45 respectively. Note that even when embedding Python in another program, <a href="http://www.python.org/doc/current/ext/extending-with-embedding.html" target="_top">extension 46 modules are often the best way to make C/C++ functionality accessible to 47 Python code</a>, so the use of extension modules is really at the heart 48 of both models. 49 </p> 50<p> 51 Except in rare cases, extension modules are built as dynamically-loaded libraries 52 with a single entry point, which means you can change them without rebuilding 53 either the other extension modules or the executable containing <code class="computeroutput"><span class="identifier">main</span><span class="special">()</span></code>. 54 </p> 55</div> 56<table xmlns:rev="http://www.cs.rpi.edu/~gregod/boost/tools/doc/revision" width="100%"><tr> 57<td align="left"></td> 58<td align="right"><div class="copyright-footer">Copyright © 2002-2015 David 59 Abrahams, Stefan Seefeld<br>Copyright © 2002-2015 David Abrahams, Stefan Seefeld<p> 60 Distributed under the Boost Software License, Version 1.0. (See accompanying 61 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>) 62 </p> 63</div></td> 64</tr></table> 65<hr> 66<div class="spirit-nav"> 67<a accesskey="p" href="../building.html"><img src="../images/prev.png" alt="Prev"></a><a accesskey="u" href="../building.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="no_install_quickstart.html"><img src="../images/next.png" alt="Next"></a> 68</div> 69</body> 70</html> 71