[Mono-devel-list] How to use shared library with C# on linux
Bernie Solomon
bernard at ugsolutions.com
Wed Nov 19 12:42:14 EST 2003
To DllImport a function by its plain name means that the function must not
have a mangled named and hence if in C++ must be extern "C" (alternatively
you could set EntryPoint to the mangled name if you really only want to
run with one platform/compiler combination but this is very unportable).
Bernie Solomon
----- Original Message -----
From: "Daniel Schalk" <daniel at schalk.de>
To: <mono-devel-list at lists.ximian.com>
Sent: Wednesday, November 19, 2003 9:23 AM
Subject: [Mono-devel-list] How to use shared library with C# on linux
> 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?
>
> 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.
>
> Thanks a lot,
> Dan
>
>
>
>
>
>
>
>
>
>
>
> _______________________________________________
> 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