SWIG with C# on Linux Mint 11

SWIGのインストールはLinuxならお馴染みの
./configure
make
make install
で行くはずなのですが、デフォルトではPerlのライブラリが足りません。
そこでソフトウェア管理からPerlの開発用のライブラリをインストールしましょう。
ファイル名は忘れてしまいました(^_^;)
Makefileが作れないとエラーが出るはずなのでそれをチェックです!
インストールが成功すればさっそくチュートリアルに挑戦します。
次の流れでうまくいきました。
まずは次の3つのファイルを用意ます…。

                                                                                                                  • -

/* File : example.c */
#include

double My_variable = 3.0;

int fact( int n ){
if( n <= 1 ) return 1;
else return ( n * fact( n - 1 ) );
}

int my_mod( int x, int y ){
return ( x % y );
}

char* get_time(){
time_t ltime;
time( <ime );
return ctime( <ime );
}

                                                                                                                  • -
                                                                                                                  • -

/* File : example.i */

%module example
%{
extern double My_variable;
extern int fact( int n );
extern int my_mod( int x, int y );
extern char* get_time();
%}

extern double My_variable;
extern int fact( int n );
extern int my_mod( int x, int y );
extern char* get_time();

                                                                                                                  • -
                                                                                                                  • -

/* File : 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() );
}
}

                                                                                                                  • -

そして以下のようにコマンドを実行していきます。
$ swig -csharp example.i
$ gcc -c -fpic example.c example_wrap.c
$ gcc -shared example.o example_wrap.o -o libexample.so
$ mono-csc -out:runme.exe *.cs
$ ./runme.exe
3
120
Tue Feb 21 00:56:27 2012

$
オフィシャルのSWIGチュートリアルは情報が古いので注意です!