DLL 的 MonoTouch System.EntryPointNotFoundException

问题描述:

我正在尝试使用 MonoTouch 应用程序访问的一些本机代码函数创建一个 DLL.我遵循了单点绑定使用的一般方法,您可以:

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:

  • 创建一个 xcode 项目并在其中放入一些本机代码
  • 使用 xcodebuild 构建静态库(.a 文件)
  • 使用 --link-with 运行 btouch 以制作 .dll 文件
  • 在我的 MonoTouch 应用程序中添加对 .dll 文件的引用

.. 但每当我尝试在我的应用程序中使用这些函数时,我都会收到 System.EntryPointNotFoundException.这是我尝试做的每件事的代码:

.. 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:

在 .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.

.. 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.

我已经验证 libMyStaticLibrary.a 确实 包含 SomeFunction:

I have verified that libMyStaticLibrary.a does contains SomeFunction:

~/build> nm libMyStaticLibrary.a*
00000167 T _SomeFunction

此外,当您尝试 P/Invoke SomeFunction 时,在您的库中找到的符号是 _SomeFunction>.我在某些情况下只能使用正确的前缀进行绑定

Also, the symbol found in your library is _SomeFunction while you're trying to P/Invoke SomeFunction. I had some cases where the binding was only possible with the proper prefix