PageRenderTime 36ms CodeModel.GetById 29ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 0ms

/trunk/Examples/python/index.html

#
HTML | 112 lines | 90 code | 22 blank | 0 comment | 0 complexity | 040f204328b68b543041c32f6714cf72 MD5 | raw file
  1<html>
  2<head>
  3<title>SWIG:Examples:python</title>
  4</head>
  5
  6<body bgcolor="#ffffff">
  7<H1>SWIG Python Examples</H1>
  8
  9<p>
 10The following examples illustrate the use of SWIG with Python.
 11
 12<ul>
 13<li><a href="simple/index.html">simple</a>.  A minimal example showing how SWIG can
 14be used to wrap a C function, a global variable, and a constant.
 15<li><a href="constants/index.html">constants</a>.  This shows how preprocessor macros and
 16certain C declarations are turned into constants.
 17<li><a href="variables/index.html">variables</a>. An example showing how to access C global variables from Python.
 18<li><a href="value/index.html">value</a>. How to pass and return structures by value.
 19<li><a href="class/index.html">class</a>. Wrapping a simple C++ class.
 20<li><a href="reference/index.html">reference</a>. C++ references.
 21<li><a href="pointer/index.html">pointer</a>. Simple pointer handling.
 22<li><a href="funcptr/index.html">funcptr</a>. Pointers to functions.
 23</ul>
 24
 25<h2>Compilation Issues</h2>
 26
 27<ul>
 28<li>To create a Python extension, SWIG is run with the following options:
 29
 30<blockquote>
 31<pre>
 32% swig -python interface.i
 33</pre>
 34</blockquote>
 35
 36<li>
 37Please see the <a href="../../Doc/Manual/Windows.html">Windows</a> page in the main manual for information on using the examples on Windows. <p>
 38</li>
 39
 40<li>On Unix the compilation of examples is done using the file <tt>Example/Makefile</tt>.  This
 41makefile performs a manual module compilation which is platform specific.  Typically,
 42the steps look like this (Linux):
 43
 44<blockquote>
 45<pre>
 46% swig -python interface.i
 47% gcc -fpic -c interface_wrap.c -I/usr/local/include/python1.5
 48% gcc -shared interface_wrap.o $(OBJS) -o interfacemodule.so 
 49% python
 50Python 1.5.2 (#3, Oct  9 1999, 22:09:34)  [GCC 2.95.1 19990816 (release)] on linux2
 51Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
 52&gt;&gt;&gt; import interface
 53&gt;&gt;&gt; interface.blah(...)
 54...
 55</pre>
 56</blockquote>
 57
 58<li>The politically "correct" way to compile a Python extension is to follow the steps
 59described at <a href="http://www.python.org/doc/current/ext/building-on-unix.html">www.python.org</a>
 60or in the most excellent (and shamelessly plugged) <a href="http://islab.cs.uchicago.edu/python">Python Essential Reference</a>:
 61
 62<p>
 63<ol>
 64<li>Create a file called <tt>Setup</tt> that looks like the following where $(SRCS) is filled
 65in with any other source files you need to build the extension:
 66
 67<blockquote>
 68<pre>
 69*shared*
 70interface interface_wrap.c $(SRCS)
 71</pre>
 72</blockquote>
 73<li>Copy the file <tt>Makefile.pre.in</tt> from the Python distribution.  Usually it's located 
 74in the directory <tt>/usr/local/lib/python1.5/config</tt> on a Unix machine.
 75
 76<p>
 77<li>Type the following to build the extension:
 78
 79<blockquote>
 80<pre>
 81% make -f Makefile.pre.in boot
 82% make
 83</pre>
 84</blockquote>
 85<li> And that's it.   If you are preparing an extension for distribution, you may want
 86to look at the <a href="http://www.python.org/sigs/distutils-sig/">distutils</a>.
 87</ol>
 88</ul>
 89
 90<h2>Compatibility</h2>
 91
 92The examples have been extensively tested on the following platforms:
 93
 94<ul>
 95<li>Linux
 96<li>Solaris
 97</ul>
 98
 99All of the examples were last tested with the following configuration (9/1/2000):
100
101<ul>
102<li>Sparc Solaris 2.8.
103<li>gcc-2.95.2
104<li>Python 1.6b1.
105</ul>
106
107Your mileage may vary.  If you experience a problem, please let us know by 
108contacting us on the <a href="http://www.swig.org/mail.html">mailing lists</a>.
109</body>
110</html>
111
112