MonoTouch アプリからアクセスされるネイティブ コード関数を使用して DLL を作成しようとしています。monotouch-bindings で使用される一般的な方法論に従いました。
- Xcode プロジェクトを作成し、それにネイティブ コードを配置します。
- xcodebuild でスタティック ライブラリ (.a ファイル) をビルドする
- --link-with を指定して btouch を実行し、.dll ファイルを作成します
- MonoTouch アプリに .dll ファイルへの参照を追加する
..しかし、アプリでこれらの関数を使用しようとすると、System.EntryPointNotFoundException が発生します。私がやろうとしているそれぞれのコードは次のとおりです。
.cpp ファイル内:
extern "C" {
int SomeFunction();
}
int SomeFunction() {
...
}
.a ファイルを作成するコマンド ライン
xcodebuild -project MyStaticLibrary.xcodeproj -target MyStaticLibrary -sdk iphonesimulator -configuration Release clean build
バインディングを含む .cs ファイル (NativeBindings.cs)
public class MyStaticLibraryBindings
{
[ DllImport( "__Internal" ) ] public extern static int SomeFunction();
}
DLL の AssemblyInfo.cs
using System;
using MonoTouch.ObjCRuntime;
[assembly: LinkWith ("libMyStaticLibrary.a", LinkTarget.Simulator | LinkTarget.ArmV7 | LinkTarget.ArmV7s, IsCxx = true, ForceLoad = true, Frameworks = "", WeakFrameworks = "")]
.dll をビルドするコマンド ライン
btouch -x=NativeBindings.cs AssemblyInfo.cs --out=NativeBindings.dll --link-with=libMyStaticLibrary.a,libMyStaticLibrary.a
.. DLL は正常にビルドされ、私のアプリはコンパイル中に MyStaticLibraryBindings.SomeFunction 関数を認識しますが、実行時に呼び出すと System.EntryPointNotFoundException が発生します。
libMyStaticLibrary.a に SomeFunction が含まれていることを確認しました。
~/build> nm libMyStaticLibrary.a*
00000167 T _SomeFunction