[Mono-devel-list] How to use shared library with C# on linux
Daniel Schalk
daniel at schalk.de
Wed Nov 19 12:23:00 EST 2003
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
More information about the Mono-devel-list
mailing list