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