diff --git a/swigweb/tutorial.ht b/swigweb/tutorial.ht index 29c282542..fa18bd6e8 100755 --- a/swigweb/tutorial.ht +++ b/swigweb/tutorial.ht @@ -5,13 +5,13 @@ SWIG Tutorial
So you want to get going in a hurry? To illustrate the use of SWIG, -suppose you have some C functions you want added to Tcl, Perl, Python and Java. +suppose you have some C functions you want added to Tcl, Perl, Python, Java and C#. Specifically, let's say you have them in a file 'example.c'
/* File : example.c */
-#include <time.h>
+#include <time.h>
double My_variable = 3.0;
int fact(int n) {
@@ -132,7 +132,7 @@ SWIG will also generate JNI code for accessing C/C++ code from Java. Here is an
$ swig -java example.i
$ gcc -c example.c example_wrap.c -I/c/jdk1.3.1/include -I/c/jdk1.3.1/include/win32
-$ gcc -shared example.o example_wrap.o -Wl,--add-stdcall-alias -o example.dll
+$ gcc -shared example.o example_wrap.o -mno-cygwin -Wl,--add-stdcall-alias -o example.dll
$ cat main.java
public class main {
public static void main(String argv[]) {
@@ -150,6 +150,31 @@ Mon Mar 4 18:20:31 2002
$
+ Building a C# module
+SWIG will also generate code for accessing C/C++ code from C# using PInvoke. Here is an example building a C# module (shown for Linux, see the SWIG Wiki Shared Libraries page for help with other operating systems). It uses the open source DotGNU Portable.NET C# compiler which runs on most Unix systems, but works equally well using other C# compilers:
+
+
+$ swig -csharp example.i
+$ gcc -c -fpic example.c example_wrap.c
+$ gcc -shared example.o example_wrap.o -o libexample.so
+$ cscc -o runme *.cs
+$ cat runme.cs
+using System;
+public class runme {
+ static void Main() {
+ Console.WriteLine(example.My_variable);
+ Console.WriteLine(example.fact(5));
+ Console.WriteLine(example.get_time());
+ }
+}
+$ ilrun runme
+3
+120
+Tue May 13 10:45:45 2003
+
+$
+
+
SWIG for the truly lazy
As it turns out, it is not always necessary to write a special interface