SWIG:Examples:Go

# SWIG Go Examples

The following examples illustrate the use of SWIG with Go.

- simple. A minimal example showing how SWIG can be used to wrap a C function, a global variable, and a constant.
- constants. This shows how preprocessor macros and certain C declarations are turned into constants.
- variables. An example showing how to access C global variables from Go.
- enum. Wrapping enumerations.
- class. Wrapping a simple C++ class.
- reference. C++ references.
- pointer. Simple pointer handling.
- funcptr. Pointers to functions.
- template. C++ templates.
- callback. C++ callbacks using directors.
- extend. Polymorphism using directors.

## Compilation Issues

- To create a Go extension, SWIG is run with the following options:

  >     % swig -go interface.i

- On Unix the compilation of examples is done using the file `Example/Makefile`. This makefile performs a manual module compilation which is platform specific. When using the `6g` or `8g` compiler, the steps look like this (GNU/Linux):

  >     % swig -go interface.i
  >     % gcc -fpic -c interface_wrap.c
  >     % gcc -shared interface_wrap.o $(OBJS) -o interfacemodule.so
  >     % 6g interface.go
  >     % 6c interface_gc.c
  >     % gopack grc interface.a interface.6 interface_gc.6
  >     % 6l program.6

- When using the `gccgo` compiler, the steps look like this:

  >     % swig -go interface.i
  >     % gcc -c interface_wrap.c
  >     % gccgo -c interface.go
  >     % gccgo program.o interface.o interface_wrap.o

  ## Compatibility

  The examples have been extensively tested on the following platforms:
  - GNU/Linux
  All of the examples were last tested with the following configuration (10 May 2010):
  - Ubuntu Hardy
  - gcc-4.2.4
  Your mileage may vary. If you experience a problem, please let us know by contacting us on the mailing lists.