I am attempting to get a Native C/C++ library working with Monodroid in the emulator, using DllImport. I am developing mainly in Windows/Visual Studio 2010.
I have built
Ok, I finally got it working! For whatever reason, ZeroMQ doesn't build correctly using the current/latest NDK r7. The instructions at http://www.zeromq.org/build:android use NDK r6. I also downloaded an old version of the NDK r5b (it was the easiest old version to find a download for), and rebuilt ZeroMQ using it. Result, it now works on emulator and phone!
I don't have any immediate ideas why it isn't working for you; [DllImport("zmq")]
should work.
The SanityTests sample exercises the DllImport
attribute.
DllImport
: https://github.com/xamarin/monodroid-samples/blob/master/SanityTests/Hello.cs#L240Android.mk
to build libfoo.so
: https://github.com/xamarin/monodroid-samples/blob/master/SanityTests/jni/Android.mklibfoo.so
by calling ndk-build
: https://github.com/xamarin/monodroid-samples/blob/master/SanityTests/SanityTests.csproj#L82libfoo.so
into the .apk
: https://github.com/xamarin/monodroid-samples/blob/master/SanityTests/SanityTests.csproj#L96(This is a repeat of my reply to your email in the ZeroMQ mailing list).
This error could be caused by using an incorrect platform target in your Mono project. I'm not sure if Mono/MonoDevelop supports this, but you probably need to create an ARM platform target, as opposed to x86/x64/Any CPU.
You would experience the same errors if you tried to do P/Invoke interop between an x64-targeted assembly with an x86 native library or vice-versa.
If you're using the clrzmq bindings for bridging Mono and libzmq, you will need to create a new platform target for ARM and rebuild the bindings. The solution only defines x86 and x64 platform targets currently.