[Mono-devel-list] How to use shared library with C# on linux

Bernie Solomon bernard at ugsolutions.com
Wed Nov 19 15:29:37 EST 2003


Of course LD_LIBRARY_PATH is in the equation too. You may need
to set this depending on what directories everything lives in.

Bernie

----- Original Message ----- 
From: "Gonzalo Paniagua Javier" <gonzalo at ximian.com>
To: "Mono Development" <mono-devel-list at lists.ximian.com>
Sent: Wednesday, November 19, 2003 11:45 AM
Subject: Re: [Mono-devel-list] How to use shared library with C# on linux


> El mié, 19-11-2003 a las 18:23, Daniel Schalk escribió:
> > Hi,
> >
> > I'm trying to code a C# app, which calls a C-function out of a shared
> > library (e.g. testlib.so).
> > In the testlib.cc i placed the following code:
> >
> > #include <stdio.h>
> >
> > void fktTest(void)
> > {
> > printf("called fktTest");
> > }
> >
> > I compiled it with: gcc -c -fpic testlib.cc
> > then: gcc -shared -fpic -o testlib.so testlib.o
> >
> > Now I created LibTest.cs:
> >
> > using System;
> > using System.Runtime.InteropServices;
> >
> > namespace LibTest
> > {
> >  class LibraryTest
> >  {
> >   [DllImport("testlib", EntryPoint="fktTest")]
> >   public static extern void fktTest();
> >
> >   static void Main(string[] args)
> >   {
> >    fktTest();
> >   }
> >  }
> > }
> >
> > I compiled it with : mcs LibTest.cs
> > So far, there were no errors. Because I'm novice on linux (and mono
:-)),
> > was it right, what I did so far? Are there any faults within my
code/doing?
>
> No, except for the .cc already pointed out.
>
> > Further questions:
> > How do I have to go on to get running my application?
> > Where to place the .so file?
> >
> > Because if I run the app with the .so in the same directory, I get error
> > "unhandeled exception: System.MissingMethodException ...").
> > What is wrong? After one day of "googling", I didn't find a solution.
>
> I generated the .so as you did and used your test program. It worked
> right away.
>
> IF it still doesn't work for you, try this command when linking:
>
> gcc -shared -fpic -o libtestlib.so testlib.o
>
> and that will probably work.
>
> -Gonzalo
>
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>




More information about the Mono-devel-list mailing list