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

Antonio Martínez Alvarez amartinez at atc.ugr.es
Fri Jul 22 05:26:10 EDT 2005


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
        private static extern int diesther ();

        public static void Main()
                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

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
 MCS version   

This is the result ... Any ideas ?
Unhandled Exception: System.DllNotFoundException: liboctivate
in (wrapper managed-to-native) kkkkk.Prueba:diesther ()
in <0x00012> kkkkk.Prueba:Main ()

Thanks in advance !!
Antonio Martinez

More information about the Mono-list mailing list