swig + mono: erros de exemplo em C # de não encontrar a biblioteca

Eu uso o swig 2.0.1 + mono 2.6 / 2.8 no Mac OS X 10.6.4.

A compilação geral está OK, e a compilação dos exemplos de C # também está OK. O problema é que, quando executo o exemplo (mono runme.exe), sempre recebo os seguintes erros.

Unhandled Exception: System.TypeInitializationException: An exception was thrown by the type initializer for examplePINVOKE ---> System.TypeInitializationException: An exception was thrown by the type initializer for SWIGExceptionHelper ---> System.DllNotFoundException: example
  at (wrapper managed-to-native) examplePINVOKE/SWIGExceptionHelper:SWIGRegisterExceptionCallbacks_example (examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate,examplePINVOKE/SWIGExceptionHelper/ExceptionDelegate)
  at examplePINVOKE+SWIGExceptionHelper..cctor () [0x00000] in :0 
  --- End of inner exception stack trace ---
  at examplePINVOKE..cctor () [0x00000] in :0 
  --- End of inner exception stack trace ---
  at example.gcd (Int32 x, Int32 y) [0x00000] in :0 
  at runme.Main () [0x00000] in :0 

Parece que ele não encontra a biblioteca de exemplo, mas a biblioteca gerada é libexample.so.

Esta é a fonte da biblioteca para gerar libexample.so

double Foo = 3.0;
int gcd(int x, int y) {
  ...
}

Esta é a fonte C # para usar o libexample.so.

using System;

public class runme
{
    static void Main() 
    {
        int x = 42;
        int y = 105;
        int g = example.gcd(x,y);
        ...
    }
}

Essa é a função do wrapper gerada com SWIG.

/* ----------------------------------------------------------------------------
 * This file was automatically generated by SWIG (http://www.swig.org).
 * Version 2.0.1
 *
 * Do not make changes to this file unless you know what you are doing--modify
 * the SWIG interface file instead.
 * ----------------------------------------------------------------------------- */
using System;
using System.Runtime.InteropServices;

public class example {
  public static int gcd(int x, int y) {
    int ret = examplePINVOKE.gcd(x, y);
    return ret;
  }

  public static double Foo {
    set {
      examplePINVOKE.Foo_set(value);
    } 
    get {
      double ret = examplePINVOKE.Foo_get();
      return ret;
    } 
  }
}

Este é o comando a ser executado para obter a biblioteca e a execução.

gcc -c    example.c example_wrap.c 
cc -bundle -undefined suppress -flat_namespace  example.o  example_wrap.o   -o libexample.so
make -f ../../Makefile CSHARPSRCS='*.cs' CSHARPFLAGS='-nologo -out:runme.exe' csharp_compile
gmcs -nologo -out:runme.exe *.cs

O que pode estar errado? O que deve ser feito para que o mono saiba sobre o libexample.so?

ADICIONADO

Eu poderia usar "swig -csharp -dllimport" libexample.so "example.i", mas obtive o mesmo resultado. Eu anexo oexamplePINVOKE.cs.

Como está escrito nestepostar, Executei "MONO_LOG_LEVEL = depuração mono runme.exe". A mensagem diz que o mono não pode encontrar o ./libexample.so, mesmo que o arquivo exista.

Mono: DllImport loading library: './libexample.so'.
Mono: DllImport error loading library '(null)'.
SOLUÇÃO

Eu poderia alterar o Makefile no swig / Examples para resolver esse problema.

CFLAGS     = -arch i386

questionAnswers(4)

yourAnswerToTheQuestion