2

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
4

2 に答える 2

2

また、ライブラリにあるシンボルは、_SomeFunctionP/Invokeを実行しようとしているときのものですSomeFunction。バインディングが適切なプレフィックスでのみ可能である場合がありました

于 2013-03-05T08:32:48.150 に答える
1

If the problem happens on a device, it's because you're building the native library for the simulator only, while you're building the dll for armv7, armv7s and the simulator. You need to build the native library 3 times, once for each targetted architecture, the lipo them together:

lipo -create -output libMyStaticLibrary.a libMyStaticLibrary-armv7.a libMyStaticLibrary-armv7s.a libMyStaticLibrary-simulator.a
于 2013-03-05T08:19:41.213 に答える