[Gtk-sharp-list] Strange error with a simple pinvoke and g++ 4.0

Rafael Teixeira monoman at gmail.com
Fri Jul 22 10:44:06 EDT 2005


I think you need to drop the 'lib' prefix in the dllimport, as it is
already added by the runtime in non-windows platforms.

    [DllImport("octivate")]
    private static extern int diesther ();

In windows .net & mono will search for octivate.dll in local directory
and in the path.

In *nix mono will ld to search for liboctivate.so, so if ldconfig was
called it should be OK.

I recommend you to read:

http://www.mono-project.com/Interop_with_Native_Libraries

:) 

On 7/21/05, amartinez at atc.ugr.es <amartinez at atc.ugr.es> wrote:
> Hello,
> 
> I don't understand the DllNotFound exception when I compile an run this
> little program which uses pinvoke.
> 
> ---------<file mylib2.cc>----------
> #include <iostream>
> using namespace std;
> extern "C" int  diesther ()
> {
>         cout << " Esther " << endl;
>         return 7;
> }
> ---------</file mylib2.cc>----------
> 
> 
> ---------------<file test_mylib2.cs>-------
> using System;
> using System.Runtime.InteropServices;
> 
> namespace kkkkk
> {
>   public class Prueba
>   {
>         [DllImport("liboctivate")]
>         private static extern int diesther ();
> 
>         public static void Main()
>         {
>                 Console.Write("Hola");
>                 diesther ();
>         }
>   }
> }
> ---------------</file test_mylib2.cs>-------
> 
> I follow these commands to compile and run ...
> 
> 
> g++ -fpic -c -I/usr/include/octave-2.9.3 mylib2.cc
> g++ -shared -o liboctivate.so mylib2.o
> rm /usr/lib/liboctivate.so
> cp liboctivate.so /usr/lib
> ldconfig -n /usr/lib
> mcs test_mylib2.cs
> mono test_mylib2.exe
> 
> 
> 2 usefuls outputs to debug the/my error:
> #ldconfig -p|fgrep liboctivate
>         liboctivate.so (libc6) => /usr/lib/liboctivate.so
> #cat /usr/lib/liboctivate.so| strings | grep diesther
> diesther
> _GLOBAL__I_diesther
> diesther
> 
> 
> I have probed with and without extern "C" and with gcc instead of g++ to
> creat the liboctivate.so library.
> 
> I have:
>  gcc and g++ version     4.0.1 (Debian 4.0.1-2)
>  Linux kernel version    2.6.11-1-686
>  Mono version version    1.1.8.2
>  MCS version             1.1.8.0
> 
> 
> 
> This is the result ... Any ideas ?
> ----------<output>---------------
> Hola
> Unhandled Exception: System.DllNotFoundException: liboctivate
> in (wrapper managed-to-native) kkkkk.Prueba:diesther ()
> in <0x00012> kkkkk.Prueba:Main ()
> ----------</output>---------------
> 
> 
> Thanks in advance !!
> ---
> Antonio Martinez
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
> 


-- 
Rafael "Monoman" Teixeira
---------------------------------------
I'm trying to become a "Rosh Gadol" before my own eyes. 
See http://www.joelonsoftware.com/items/2004/12/06.html for enlightment.
It hurts!


More information about the Gtk-sharp-list mailing list