[Mono-osx] P/invoke 32-bit C library
andy at britishideas.com
Wed Sep 14 10:27:32 EDT 2011
Hi, Sorry for all the questions today... :(
I have a 32-bit C-based library that I can compile under Windows and use
with a C# wrapper in my .NET applications. The calling convention is
cdecl. This works fine.
I have recompiled the library using gcc in MonoDevelop and called it
from a C-based console application, also using gcc in MonoDevelop, on OS
X. This works fine also. I use -m32 to make everything 32-bit so cdecl
can continue to be used.
Now I want to use it from C# on OS X. I've renamed the library from
libfoo.so to Foo.dll, which is what it is called when compiled for
Windows. I believe this should allow me to use my simple C# wrapper that
I use in Windows without having to recompile it. However I get a
System.EntryPointNotFoundException for _fm_connect.
nm Foo.DLL shows:
00007a14 T _fm_connect
Here is how I import it in the C# wrapper:
const String DLLName = "Foo.dll"
[DllImport(DLLName, EntryPoint = "_fm_connect",
CallingConvention = CallingConvention.Cdecl,
ExactSpelling = false, CharSet = CharSet.Ansi,
SetLastError = true)]
static extern unsafe IntPtr fm_connect(IntPtr options, Int32 optionssize);
So to summarize:
- The C library and C# wrapper work fine in Windows with Visual Studio.
- The C library works fine on OS X when called from a C application.
- The C# wrapper can't find this function when using on OS X.
PGP Key ID: 0xDC1B5864
More information about the Mono-osx