Reputation: 2887
I am new to using .NET, but I am interested in using MonoTouch/Droid to write mobile applications that could share some core code.
I have many C style API libraries I wish to use, for example libxml2. How do I call these native library methods in Mono? Can I use the same binaries compiled from Windows if I am developing in Windows? Can I use the Windows binaries if I am developing in OS X?
Upvotes: 4
Views: 971
Reputation: 43553
How do I call these native library methods in Mono?
You use p/invoke (platform invoke) to call native C code from any .NET language. You need to write those declarations (of find someone who did it before you) to use the native libraries. Like @Marcelo commented there are often very good, much easier to use .NET alternatives to most C libraries.
This will work on MonoTouch too. However you'll need provide a static library (.a
on OSX, like a .lib
on Windows) since Apple iOS does not allow linking with user-provided dynamic libraries (.dylib
on OSX/iOS and .dll
on Windows).
Can I use the same binaries compiled from Windows if I am developing in Windows?
Windows produced binaries should run fine with Mono on Windows. You can use Microsoft .NET on Windows too.
Can I use the Windows binaries if I am developing in OS X?
If the binaries are .NET compiled code then yes - as long as your p/invoke declrations are portable (e.g. 32 vs 64 bits types).
If the binaries are native code then no. Remember that Mono is not a Windows emulator. It runs CIL code, inside .EXE or .DLL, but it won't run native Windows code or provide access to Windows native API (outside Windows).
Upvotes: 7