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

Chris Turchin chris at turchin.net
Wed Nov 19 17:37:39 EST 2003

Hi all, 

to clear this up for myself (not being a c-programmer shared libs
are/were foreign to me) I wrote a little sample based on Daniel's work
creating a shared library, then using it in a c program and finally
DLLImporting it into a csharp program as well. I needed much more time
getting it to work in c than csharp but that is likely due to the fact
that the last time I delved into the subject was in CS141 back in


What I found out:

> I think the problem in this case is that the runtime doesn't have a
> mapping set up to find the library; you're going to need to edit
> /etc/mono/config and add a <dllmap> entry. (As far as I know, there's no
> way to extend this scheme, which seems like it could be a big problem
> for third-party apps to me).

This doesn't seem to be true. I simply set LD_LIBRARY_PATH to include
the lib dir in question and things worked. I think I needed to do this
to compile/run the c-program as well...

I also ran into the "mono wants to append 'lib' to the to-be-imported
library name problem". To solve it, I just renamed the lib (libtest.so)
and then did [DllImport("test")] instead.

It works now for me in my simple c and csharp app. Maybe this
mini-tutorial can help someone else out there to understand it too. 


ps: yes, i know the c-code and the makefile probably are horrid, but it
works for me :-P

pps:btw, if its relevant: I am testing this on a Mandrake 9.1 system
with gcc 3.2.2 and 0.28 mono from redcarpet.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: interoptest.tar.bz2
Type: application/x-bzip-compressed-tar
Size: 10240 bytes
Desc: not available
Url : http://lists.ximian.com/pipermail/mono-devel-list/attachments/20031119/186f477d/attachment.bin 

More information about the Mono-devel-list mailing list