I'm trying to make a DLL with some native code functions that are accessed by my MonoTouch app. I followed the general methodology used by monotouch-bindings, where you:
- make an xcode project and put some native code in it
- build a static library (.a file) with xcodebuild
- run btouch with --link-with to make a .dll file
- add a reference to the .dll file in my MonoTouch app
.. but whenever I try to use these functions in my app, I get System.EntryPointNotFoundException. Here's code for each thing I'm trying to do:
In the .cpp file:
extern "C" {
int SomeFunction();
}
int SomeFunction() {
...
}
Command line to build the .a file
xcodebuild -project MyStaticLibrary.xcodeproj -target MyStaticLibrary -sdk iphonesimulator -configuration Release clean build
The .cs file (NativeBindings.cs) with the bindings
public class MyStaticLibraryBindings
{
[ DllImport( "__Internal" ) ] public extern static int SomeFunction();
}
AssemblyInfo.cs for the DLL
using System;
using MonoTouch.ObjCRuntime;
[assembly: LinkWith ("libMyStaticLibrary.a", LinkTarget.Simulator | LinkTarget.ArmV7 | LinkTarget.ArmV7s, IsCxx = true, ForceLoad = true, Frameworks = "", WeakFrameworks = "")]
The command line to build the .dll
btouch -x=NativeBindings.cs AssemblyInfo.cs --out=NativeBindings.dll --link-with=libMyStaticLibrary.a,libMyStaticLibrary.a
.. the DLL builds fine, and my app sees the MyStaticLibraryBindings.SomeFunction function during compilation, but at runtime when I call it, I get System.EntryPointNotFoundException.
I have verified that libMyStaticLibrary.a does contains SomeFunction:
~/build> nm libMyStaticLibrary.a*
00000167 T _SomeFunction