From AuroraUX

(Redirected from Swig)
Jump to: navigation, search

SWIG

The Simplified Wrapper and Interface Generator (SWIG) is a C/C++ library binding generator with early Ada support. It generates either wrapper-based or binary (ABI) bindings.

Ada support is available in the subversion tree and can be checked out:

svn co https://gnuada.svn.sourceforge.net/svnroot/gnuada/trunk/projects/swig-1.3.35 swig

Notes

Basic Steps

  1. Build SWIG its self.
  2. Create a swig config file (xyz.i)
  3. The '.i' file lists the C headers you want swig to generate a binding for (more or less)

To invoke SWIG to build a binding:

  • swig_gnat -gnat xyz.i

SWIG Config .i File

Basic format of a .i file is as follows:

/* File : xyz.i */
%module InterfaceName_xyz


// This section will be placed in the generated c++ support file.
// It should #include any headers needed by the binding.
//
%{
#include <sys/fs/zfs.h>
#include <libzfs.h>
%}



// Corresponding Ada declarations will be created for each C declaration in
// these %include'd directives.
//
%include <sys/fs/zfs.h>
%include <sys/avl.h>
%include <ucred.h>

%include <libzfs.h>



// Custom C declarations.
// These are functions you can add to extend the C library.
// Ada bindings will be created for each declaration.
//
%inline 
%{
  extern int    MyFunc(int x, int y);
  extern double MyGlobalVariable;
%}

References

External

SWIG A guide to writing Ada bindings to C code.